Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lm15/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,12 @@ class ResolvedOpenAIResponsesCompat:
# "reasoning_effort" only.
OpenAIChatReasoningOff = Literal["auto", "send", "lowest", "switch"]
# Whether the server honours response_format.type=json_schema. "reject"
# raises before the wire. DeepSeek answers 400 (loud, nothing to do); Z.AI
# answers 200 with free-form, fenced JSON that ignores the schema (live
# 2026-09-03) — silent, so the adapter must refuse.
# keeps it off the wire. Z.AI answers 200 with free-form, fenced JSON that
# ignores the schema (live 2026-09-03) — silent, so the adapter must refuse.
# DeepSeek answers 400 (chat--create.md: response_format.type is text or
# json_object); the error is loud, but callers that read this knob to pick a
# format before the call (DSPy's JSONAdapter) need it to say so, or every
# structured-output request to DeepSeek fails.
# "none": the server applies no response_format at all — json_schema and
# json_object both answered 200 with free text on every Tinker family
# (live 2026-11-09, receipts/2026-11-09-tinker-survey/): either type is
Expand Down Expand Up @@ -788,6 +791,7 @@ def preset_base_url(table: dict[str, str], name: str, *, dialect: str, default_p
strict_tools="omit",
cache_control="none",
user_field="user_id",
json_schema="reject", # response_format.type is text or json_object (chat--create.md); json_schema is a 400
tool_result_media="reject", # MAP-10: HTTP 200 and the model sees [Unsupported Image] — silent degrade
),
"qwen": OpenAIChatCompat(
Expand Down
11 changes: 6 additions & 5 deletions lm15/providers/openai_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,12 +1544,13 @@ def _payload(self, request: Request, stream: bool) -> dict[str, Any]:
"and applies no response_format at all; describe the shape in the prompt",
asked=request.config.response_format, provider=self.provider)
elif compat.json_schema == "reject" and request.config.response_format["type"] != "json_object":
# The server accepts response_format.type=json_schema and
# ignores it (Z.AI, live 2026-09-03: HTTP 200, fenced JSON with
# keys the schema never named). json_object is honoured.
# The server does not apply response_format.type=json_schema:
# Z.AI accepts and ignores it (live 2026-09-03: HTTP 200, fenced
# JSON with keys the schema never named); DeepSeek answers 400
# (chat--create.md). json_object is honoured by both.
adapt("config.response_format", "dropped",
f"this server accepts response_format type {request.config.response_format['type']!r} "
"and does not apply it; use {'type': 'json_object'} and describe the shape in the prompt",
f"this server does not apply response_format type {request.config.response_format['type']!r}; "
"use {'type': 'json_object'} and describe the shape in the prompt",
asked=request.config.response_format, provider=self.provider)
else:
# MAP-14: the judgment convention goes verbatim on the chat
Expand Down
16 changes: 16 additions & 0 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ def test_deepseek_declaration(self) -> None:
assert compat.assistant_reasoning_content == "include_empty"
assert compat.max_tokens_field == "max_tokens"
assert compat.user_field == "user_id"
# response_format.type is text or json_object (chat--create.md); a
# json_schema body is answered 400, so the preset says so up front.
assert compat.json_schema == "reject"

def test_deepseek_keeps_json_schema_off_the_wire(self) -> None:
from lm15 import Config, Message, Request

from tests._adapt import adapted
lm = LMRouter(RouterConfig(env={"DEEPSEEK_API_KEY": "k"})).lm("deepseek:deepseek-flash")
def req(cfg):
return Request(model="deepseek-flash", messages=(Message.user("answer in json"),), config=cfg)
out = adapted(lm, req(Config(response_format={"type": "json_schema", "name": "x", "schema": {"type": "object"}})))
assert out["config.response_format"].action == "dropped" and "response_format" not in out["__body__"]
# JSON mode is DeepSeek's structured-output path and still goes out.
out = adapted(lm, req(Config(response_format={"type": "json_object"})))
assert "config.response_format" not in out and out["__body__"]["response_format"] == {"type": "json_object"}

def test_user_field_rides_the_compat_name(self) -> None:
# DeepSeek documents `user_id` and accepts `user` silently (live
Expand Down