Skip to content

DeepSeek: json_schema is a 400, so the preset says json_schema="reject" - #35

Open
chaitanya0305 wants to merge 1 commit into
lm15-dev:mainfrom
chaitanya0305:fix/deepseek-json-schema-reject
Open

chaitanya0305 wants to merge 1 commit into
lm15-dev:mainfrom
chaitanya0305:fix/deepseek-json-schema-reject

Conversation

@chaitanya0305

Copy link
Copy Markdown

Fixes #34

Why

DeepSeek's Chat Completions API takes response_format.type text or json_object (chat--create.md; https://api-docs.deepseek.com/api/create-chat-completion, https://api-docs.deepseek.com/guides/json_mode). The OpenAIChatJsonSchema comment already records that DeepSeek answers 400, but the deepseek preset left the knob unset. Callers that read the knob before the call therefore cannot see the limit. DSPy's capability check (compat.json_schema == "reject" makes supports_response_schema False) falls through to LiteLLM metadata that says True. dspy.JSONAdapter then sends json_schema, and every structured-output call to DeepSeek fails, including ChatAdapter's JSON fallback.

Change

  • lm15/compat.py: deepseek preset gains json_schema="reject", citing chat--create.md. The OpenAIChatJsonSchema comment now explains why a loud 400 still gets the knob.
  • lm15/providers/openai_chat.py: the "reject" branch's comment and adaptation reason no longer say the server "accepts and ignores" json_schema, which was true only for Z.AI. The reason now reads "this server does not apply response_format type 'json_schema'; use {'type': 'json_object'} ...".
  • tests/test_registry.py: test_deepseek_declaration asserts json_schema == "reject". The new test_deepseek_keeps_json_schema_off_the_wire checks that json_schema is dropped and recorded, and that json_object still goes out unchanged.

Behaviour for direct lm15 users: a json_schema request to DeepSeek is now sent without response_format, with an adaptation record, as Z.AI already is, instead of coming back as a 400. Under adaptations="refuse" it raises before the wire.

Tests

  • pytest tests/test_registry.py -k deepseek: on origin/main source, 2 failed and 1 passed. With the fix, 3 passed.
  • pytest tests/ (ignoring the two modules that need a sibling lm15-contract checkout): 3187 passed, 43 skipped. The 2 remaining failures in test_cross_provider_review.py (tinker) are the same missing-contract-file errors as on origin/main.
  • The pinned contract (4b155c7f) has no cases/deepseek/*json_schema* case, so no fixture changes.
  • Downstream check: with the same one-line preset change in DSPy's vendored copy, dspy.JSONAdapter on deepseek/deepseek-flash sends {"type": "json_object"} and succeeds. Without it, it raises LMInvalidRequestError.

…_format.type is text or json_object, chat--create.md), so the preset sets json_schema="reject": the request goes out without it, recorded as dropped, and a caller that reads the knob before the call (DSPy's JSONAdapter) asks for JSON mode instead of failing

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeepSeek preset: json_schema unset, so capability readers (DSPy JSONAdapter) send a request DeepSeek always rejects

1 participant