Repository navigation
fix(anthropic): JSON mode never forces a tool the newer Claude models refuse - #38
Closed
pseudotensor wants to merge 2 commits into
Closed
pseudotensor wants to merge 2 commits into
pseudotensor wants to merge 2 commits into
Conversation
* fix(anthropic): route native structured output Use model capability metadata so new native structured-output models do not require transformation allowlist changes. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(anthropic): pass provider to capability Co-authored-by: Cursor <cursoragent@cursor.com> * test(anthropic): cover dotted model IDs Co-authored-by: Cursor <cursoragent@cursor.com> * fix(anthropic): handle remote capability lag Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com> (cherry picked from commit 477ef3a)
… refuse
Claude Opus 5.5 (and Fable 5.1) think on every request and refuse a forced tool --
`400 tool_choice: type "tool" and "any" are not supported for this model`. Measured in h2oGPTe CI
(2026-09-29): 81 such refusals in one smoke run, every JSON-mode sub-call (query rewrite,
classification) returning `{}` after two retries.
On top of the cherry-picked upstream BerriAI#33235 (native structured output chosen by the model map's
`supports_native_structured_output`, not a name list that stopped at opus-4-7 / sonnet-4-6):
* model map (both copies): the entries upstream has for claude-opus-5-5, claude-opus-5,
claude-fable-5-1 and claude-mythos-5 -- prices unchanged from upstream, and without the fields
this fork's code does not read -- and `supports_native_structured_output: true` on
claude-sonnet-5, claude-fable-5 and claude-haiku-4-5(-20251001), as upstream marks them.
`supports_forced_tool_use: false` on opus-5-5 and fable-5-1, as upstream.
* `AnthropicModelInfo.forced_tool_use_unsupported`: an explicit `supports_forced_tool_use: false`.
JSON mode on such a model offers the JSON tool without forcing it.
* `_apply_forced_tool_choice`: a caller's own forced tool_choice on such a model is downgraded to
`auto` under drop_params (with a warning), and otherwise refused client-side with a 400 that says
how -- as upstream does.
Tests: tests/test_litellm/llms/anthropic/chat/test_claude_json_mode_never_forces_a_tool_it_refuses.py
(native output for the eight newer models, the guard alone, the unchanged legacy path, the caller
downgrade and refusal); the model-map schema gains `supports_forced_tool_use`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
Superseded by #40, which syncs h2o-main to upstream v1.99.4 and carries this fix on top. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claude Opus 5.5, and upstream says Fable 5.1 too, thinks on every request and refuses a forced tool:
This fork picks native structured output from a hard-coded name list that stops at opus-4-7 / sonnet-4-6. So JSON mode (
response_formatwith a schema) on every newer Claude falls back to the forced JSON tool, and that request is refused. h2oGPTe CI hit exactly this error on 2026-09-29: 81 refusals from claude-opus-5-5 in one smoke run. The refused JSON sub-calls came back{}after two retries.What changes
Everything below is taken from upstream LiteLLM
main, where these fixes already landed.supports_native_structured_output, not a name list.claude-opus-5-5,claude-opus-5,claude-fable-5-1andclaude-mythos-5. Prices are upstream's. Fields this fork's code doesn't read are left out, so the map schema is unchanged apart from one new key.supports_native_structured_output: trueonclaude-sonnet-5,claude-fable-5andclaude-haiku-4-5(-20251001), as upstream marks them.supports_forced_tool_use: falseonclaude-opus-5-5andclaude-fable-5-1, as upstream marks them.AnthropicModelInfo.forced_tool_use_unsupported. It is true only when the map explicitly sayssupports_forced_tool_use: false. JSON mode on such a model offers the JSON tool without forcing it. An unmapped model keeps today's behaviour._apply_forced_tool_choice. A caller's own forcedtool_choice(requiredor a named tool) on such a model is downgraded toautounderdrop_params, with a warning. Withoutdrop_paramsit's refused client-side with a 400 that says what to do. This matches upstream.Tests
New file:
tests/test_litellm/llms/anthropic/chat/test_claude_json_mode_never_forces_a_tool_it_refuses.py. It covers:The model-map schema in
tests/test_litellm/test_utils.pygainssupports_forced_tool_use.Local results:
tests/test_litellm/llms/anthropic/,test_utils.py,test_claude_opus_4_8_config.pyandtests/test_litellm/llms/bedrock/chat, run withLITELLM_LOCAL_MODEL_COST_MAP=True.h2o-maintoo, becausevertexaiisn't installed on that machine.ruff checkis clean on the changed code, andscripts/ruff_strict_gate.py --base h2oai/h2o-mainpasses.Scope
LITELLM_FORK_SHA, bumped after merge).inference_server: anthropicpath, which forcestool_choice={"type":"tool","name":"JSON"}itself (h2ogpt_internalsrc/gpt_langchain.py). That's a separate fix.🤖 Generated with Claude Code