diff --git a/lm15/compat.py b/lm15/compat.py index cf0a963..dcf46c2 100644 --- a/lm15/compat.py +++ b/lm15/compat.py @@ -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 @@ -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( diff --git a/lm15/providers/openai_chat.py b/lm15/providers/openai_chat.py index b532482..948882b 100644 --- a/lm15/providers/openai_chat.py +++ b/lm15/providers/openai_chat.py @@ -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 diff --git a/tests/test_registry.py b/tests/test_registry.py index b54bcc9..91937e7 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -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