Repository navigation
fix(bedrock): stop leaking Anthropic thinking/reasoning_effort into DeepSeek Converse requests - #33409
Conversation
…odelRequestFields for DeepSeek
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThis PR corrects Bedrock Converse reasoning-parameter handling and preserves JSON-mode response transformation.
Confidence Score: 5/5The PR appears safe to merge; no outstanding correctness, security, or repository-rule issue remains. The current implementation prevents unsupported DeepSeek fields from reaching Bedrock, forwards DeepSeek V3 reasoning effort in the accepted raw shape, preserves other model families, and correctly carries JSON mode into response processing. The sole previous finding was manually resolved and is not outstanding.
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/converse_transformation.py | Correctly specializes Bedrock reasoning-parameter advertisement and mapping for DeepSeek while preserving other reasoning-model paths and explicit JSON-mode handling. |
| tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py | Adds targeted, network-free regression tests covering parameter advertisement, request shaping, non-DeepSeek preservation, GPT-6 detection, and JSON-mode response handling. |
Reviews (4): Last reviewed commit: "Merge branch 'litellm_internal_staging' ..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@greptile review again |
…itellm_fix_bedrock_deepseek_thinking_leak
mateo-berri
left a comment
There was a problem hiding this comment.
This will cause a regression. It's not gating the drop on DeepSeek only so Claude behind application-inference-profile ARNs, gpt-oss-safeguard, and Nova 2 custom-import ARNs will all silently degrade reasoning in prod
…lowlisted models The DeepSeek leak fix gated the drop of thinking/reasoning_effort on a positive allowlist (_model_accepts_anthropic_thinking_param). Its negation dropped the params for any model the allowlist and ARN introspection missed, so Claude behind application-inference-profile ARNs, gpt-oss-safeguard (absent from the cost map so supports_reasoning is False), and Nova 2 custom-import ARNs all silently lost reasoning in prod. Gate the drop on a narrow denylist instead: only DeepSeek reasons natively and 400s on the request field, so drop only there and leave every other model (including opaque ARNs and gpt-oss/Nova 2 which route reasoning_effort through their own shapes) untouched. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…seek_thinking_leak
|
❌ Cannot revive Devin session - the session is too old. Please start a new session instead. |
|
bugbot run |
…seek_thinking_leak
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 263c34f. Configure here.
TLDR
Problem this solves:
thinkingorreasoning_effortis sentthinkingblock to every "reasoning" modelreasoning_effortdid nothingHow it solves it:
thinkingparamreasoning_effort, so callers get a clear client-side errorreasoning_effortraw, the way gpt-oss does, and reasoning actually turns onmap_openai_paramsdrops the fields for direct calls too, so nothing leaksUser Flow
Before: a developer calling DeepSeek R1 on Bedrock through the gateway gets an opaque AWS error the moment they ask for reasoning, and DeepSeek V3 quietly ignores the ask
POST https://litellm-domain/v1/chat/completionswith"model": "bedrock-deepseek-r1"and"thinking": {"type": "enabled", "budget_tokens": 1024}BedrockException - {"message":"The model returned the following errors: Validation Error"}, no hint of which field AWS rejected"reasoning_effort": "high"instead, and withdrop_params: trueon the deployment, and get the same opaque 400 every timePOST https://litellm-domain/v1/messageswith the same model andthinkingblock and get the same 400"model": "bedrock-deepseek-v3"with"reasoning_effort": "high"and get HTTP 200, butreasoning_contentis null and the answer used 2 completion tokens: no reasoning happenedAfter: the same developer gets a clear error naming the unsupported field, a working call once they drop it, and real reasoning from DeepSeek V3
POST https://litellm-domain/v1/chat/completionswith"model": "bedrock-deepseek-r1"and"thinking": {"type": "enabled", "budget_tokens": 1024}bedrock does not support parameters: ['thinking'], for model=us.deepseek.r1-v1:0. To drop these, set litellm.drop_params=Truebefore anything reaches AWS"reasoning_effort": "high"anddrop_params: trueon the deployment and get HTTP 200 withreasoning_contentfilled and391in the answerPOST https://litellm-domain/v1/messageswith the same model andthinkingblock and get the same clear HTTP 400 naming the field, and on thedrop_params: truedeployment HTTP 200 with athinkingblock followed by atextblock"model": "bedrock-deepseek-v3"with"reasoning_effort": "high"and get HTTP 200 withreasoning_contentfilled and 151 completion tokens: reasoning is onRelevant issues
Fixes #33401 (also covers the DeepSeek part of #13959)
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Two no-DB proxies on the config below, each booted with
--num_workers 2(2 uvicorn workers, the same topology on both legs), hitting real Bedrock with a bearer token. The before proxy runs the merge base ee7c7e1 on port 28682, the after proxy runs this PR's tip 263c34f on port 33394. 263c34f is dd707da merged withlitellm_internal_staging(conflict resolution inconverse_transformation.pyonly, no other change), so the run below is the fresh one at the merged tree.bedrock-deepseek-r1,bedrock-deepseek-v3andbedrock-deepseek-v31are plain deployments, the-dropvariants setdrop_params: true, andbedrock-claudeisus.anthropic.claude-sonnet-4-6as the controlEvery chat call below is
curl -s -o body.json -w 'HTTP %{http_code} ' http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"<model>","messages":[{"role":"user","content":"What is 17*23? Answer with just the number."}],"max_tokens":600, <param>}'followed byjq -c 'if .choices then {content: .choices[0].message.content, reasoning: (.choices[0].message.reasoning_content|tostring|.[0:60]), completion_tokens: .usage.completion_tokens} else .error.message[0:260] end' body.json./v1/messagescalls add-H 'anthropic-version: 2023-06-01'and the Anthropic body shape with"thinking":{"type":"enabled","budget_tokens":1024}(jqprints{blocks: [.content[].type], text, output_tokens}),/v1/responsescalls send"input","max_output_tokens":2048and"reasoning":{"effort":"high"}(jqprints{types: [.output[].type], text, out_tokens}), and streaming calls add"stream":trueand print oneRperreasoning_contentdelta and oneCpercontentdeltaBefore (ee7c7e1, port 28682, 2 workers)
/v1/chat/completions, DeepSeek R1 with
thinking<param>="thinking":{"type":"enabled","budget_tokens":1024}, modelbedrock-deepseek-r1HTTP 400 "litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: Validation Error\"}. Received Model Group=bedrock-deepseek-r1"/v1/chat/completions, DeepSeek R1 with
reasoning_effort<param>="reasoning_effort":"high", modelbedrock-deepseek-r1(identical with"low")HTTP 400 "litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: Validation Error\"}. Received Model Group=bedrock-deepseek-r1"/v1/chat/completions, DeepSeek R1 with
reasoning_effort,drop_params: true<param>="reasoning_effort":"high", modelbedrock-deepseek-r1-dropHTTP 400 "litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: Validation Error\"}. Received Model Group=bedrock-deepseek-r1-drop"(drop_params did not help because the field was advertised as supported)/v1/chat/completions, DeepSeek R1 with
reasoning_effort, streaming"stream":true, modelbedrock-deepseek-r1(identical onbedrock-deepseek-r1-drop)data:chunks, justHTTP 400 {"error":{"message":"litellm.BadRequestError: BedrockException - validationException {\"message\":\"The model returned the following errors: Validation Error\"}","type":null,"param":null,"code":"400"}}/v1/messages, DeepSeek R1 with
thinking{"model":"bedrock-deepseek-r1","max_tokens":600,"messages":[...],"thinking":{"type":"enabled","budget_tokens":1024}}HTTP 400 {"type":"invalid_request_error","message":"litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: Validation Error\"}. Received Model Group=bedrock-deepseek-r1"}/v1/messages, DeepSeek R1 with
thinking,drop_params: truebedrock-deepseek-r1-dropHTTP 400 {"type":"invalid_request_error","message":"litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: Validation Error\"}. Received Model Group=bedrock-deepseek-r1-drop"}/v1/responses, DeepSeek R1 with
reasoning.effort{"model":"bedrock-deepseek-r1","input":"What is 17*23? Answer with just the number.","max_output_tokens":2048,"reasoning":{"effort":"high"}}HTTP 400 "litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: Validation Error\"}. Received Model Group=bedrock-deepseek-r1"/v1/responses, DeepSeek R1 with
reasoning.effort,drop_params: truebedrock-deepseek-r1-dropHTTP 400 "litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: Validation Error\"}. Received Model Group=bedrock-deepseek-r1-drop"/v1/chat/completions, DeepSeek V3 with
thinking<param>="thinking":{"type":"enabled","budget_tokens":1024}, modelbedrock-deepseek-v3HTTP 200 {"content":"391","reasoning":"null","completion_tokens":2}(the Anthropic-shaped block was silently ignored)/v1/chat/completions, DeepSeek V3 with
reasoning_effort<param>="reasoning_effort":"high", modelbedrock-deepseek-v3HTTP 200 {"content":"391","reasoning":"null","completion_tokens":2}(no reasoning:reasoning_effortwas translated into the Anthropic block AWS ignores)/v1/chat/completions, DeepSeek V3 with
reasoning_effort: "low"<param>="reasoning_effort":"low", modelbedrock-deepseek-v3HTTP 200 {"content":"391","reasoning":"null","completion_tokens":2}/v1/chat/completions, DeepSeek V3 with
reasoning_effort, streaming"stream":trueC/v1/messages, DeepSeek V3 with
thinking{"model":"bedrock-deepseek-v3","max_tokens":600,"messages":[...],"thinking":{"type":"enabled","budget_tokens":1024}}HTTP 200 {"blocks":["text"],"text":"391","output_tokens":2}(nothinkingblock)/v1/responses, DeepSeek V3 with
reasoning.effort{"model":"bedrock-deepseek-v3","input":"What is 17*23? Answer with just the number.","max_output_tokens":2048,"reasoning":{"effort":"high"}}HTTP 200 {"types":["message"],"text":"Let's calculate \\(17 \\times 23\\):\n\n\\[\n17","out_tokens":60}(noreasoningitem)/v1/chat/completions, DeepSeek V3.1 with
reasoning_effort<param>="reasoning_effort":"high", modelbedrock-deepseek-v31HTTP 200 {"content":"I apologize for the error in my previous response. Let me correct that.\n\n17 * 23 = 391\n\nThe correct answer is 391.","reasoning":"null","completion_tokens":31}(no reasoning;thinkingand"low"also return 200 withreasoningnull, streaming printsC)/v1/messages and /v1/responses, DeepSeek V3.1
/v1/messagesand/v1/responsesbodies as the V3 cases, modelbedrock-deepseek-v31HTTP 200 {"blocks":["text"],"text":"391","output_tokens":2}andHTTP 200 {"types":["message"],"text":"The product of 17 and 23 is:\n\n17 * 23 = ","out_tokens":25}(no reasoning on either)/v1/chat/completions and /v1/messages, Claude control with
thinking<param>="thinking":{"type":"enabled","budget_tokens":1024}, modelbedrock-claudeHTTP 200 {"content":"391","reasoning":"391","completion_tokens":13}andHTTP 200 {"blocks":["thinking","text"],"text":"391","output_tokens":13}After (263c34f, port 33394, 2 workers)
/v1/chat/completions, DeepSeek R1 with
thinking<param>="thinking":{"type":"enabled","budget_tokens":1024}, modelbedrock-deepseek-r1HTTP 400 "litellm.UnsupportedParamsError: bedrock does not support parameters: ['thinking'], for model=us.deepseek.r1-v1:0. To drop these, setlitellm.drop_params=Trueor for proxy:\n\nlitellm_settings:\n drop_params: true"(raised before the request leaves the gateway)/v1/chat/completions, DeepSeek R1 with
reasoning_effort<param>="reasoning_effort":"high", modelbedrock-deepseek-r1(identical with"low")HTTP 400 "litellm.UnsupportedParamsError: bedrock does not support parameters: ['reasoning_effort'], for model=us.deepseek.r1-v1:0. To drop these, setlitellm.drop_params=Trueor for proxy:\n\nlitellm_settings:\n drop_params: true"/v1/chat/completions, DeepSeek R1 with
reasoning_effort,drop_params: true<param>="reasoning_effort":"high", modelbedrock-deepseek-r1-dropHTTP 200 {"content":"","reasoning":"Okay, so I need to calculate 17 multiplied by 23. Let me thi","completion_tokens":600}(the field is dropped and R1 reasons natively;thinkingand"low"on this deployment also return 200 with reasoning)/v1/chat/completions, DeepSeek R1 with
reasoning_effort, streaming"stream":true, modelbedrock-deepseek-r1data:chunks, justHTTP 400 {"error":{"message":"litellm.UnsupportedParamsError: bedrock does not support parameters: ['reasoning_effort'], for model=us.deepseek.r1-v1:0. To drop these, setlitellm.drop_params=Trueor for proxy: ...","type":null,"param":null,"code":"400"}}/v1/chat/completions, DeepSeek R1 with
reasoning_effort,drop_params: true, streaming"stream":true, modelbedrock-deepseek-r1-dropRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...(reasoning deltas stream untilmax_tokens)/v1/messages, DeepSeek R1 with
thinking{"model":"bedrock-deepseek-r1","max_tokens":600,"messages":[...],"thinking":{"type":"enabled","budget_tokens":1024}}HTTP 400 {"type":"invalid_request_error","message":"litellm.UnsupportedParamsError: bedrock does not support parameters: ['reasoning_effort'], for model=us.deepseek.r1-v1:0. To drop these, setlitellm.drop_params=Trueor for proxy:\n\nlitellm_settings:\n drop_params: true\n. \n If you want to use these params dynamically send allowed_openai_params=['reasoning_effort'] in your request.. Received Model Group=bedrock-deepseek-r1\nAvailable Model Group Fallbacks=None"}(the Anthropic adapter translatesthinkingintoreasoning_effortbefore the Bedrock config sees it, so that is the field named)/v1/messages, DeepSeek R1 with
thinking,drop_params: truebedrock-deepseek-r1-dropHTTP 200 {"blocks":["thinking","text"],"text":"","output_tokens":600}(R1 spent the whole 600-token budget in its native thinking block)/v1/responses, DeepSeek R1 with
reasoning.effort{"model":"bedrock-deepseek-r1","input":"What is 17*23? Answer with just the number.","max_output_tokens":2048,"reasoning":{"effort":"high"}}HTTP 400 "litellm.UnsupportedParamsError: bedrock does not support parameters: ['reasoning_effort'], for model=us.deepseek.r1-v1:0. To drop these, setlitellm.drop_params=Trueor for proxy:\n\nlitellm_settings:\n drop_params: true"/v1/responses, DeepSeek R1 with
reasoning.effort,drop_params: truebedrock-deepseek-r1-dropHTTP 200 {"types":["reasoning","message"],"text":"\n\n391","out_tokens":441}/v1/chat/completions, DeepSeek V3 with
thinking<param>="thinking":{"type":"enabled","budget_tokens":1024}, modelbedrock-deepseek-v3HTTP 400 "litellm.UnsupportedParamsError: bedrock does not support parameters: ['thinking'], for model=deepseek.v3.2. To drop these, setlitellm.drop_params=Trueor for proxy:\n\nlitellm_settings:\n drop_params: true"(onbedrock-deepseek-v3-dropthe same call returnsHTTP 200with the worked answer andreasoningnull)/v1/chat/completions, DeepSeek V3 with
reasoning_effort<param>="reasoning_effort":"high", modelbedrock-deepseek-v3HTTP 200 {"content":"391","reasoning":"We are asked: \"What is 17*23? Answer with just the number.\" ","completion_tokens":122}(real reasoning, sincereasoning_effortnow reaches Bedrock raw)/v1/chat/completions, DeepSeek V3 with
reasoning_effort: "low"<param>="reasoning_effort":"low", modelbedrock-deepseek-v3HTTP 200 {"content":"391","reasoning":"null","completion_tokens":2}(Bedrock acceptslowand answers without reasoning)/v1/chat/completions, DeepSeek V3 with
reasoning_effort, streaming"stream":trueRRRRRRRRRRC/v1/messages, DeepSeek V3 with
thinking{"model":"bedrock-deepseek-v3","max_tokens":600,"messages":[...],"thinking":{"type":"enabled","budget_tokens":1024}}HTTP 200 {"blocks":["text"],"text":"First, note that \\(17 \\times 23\\) can be","output_tokens":73}(the adapter maps a 1024 budget toreasoning_effort: "low", which V3 answers without reasoning, same as before)/v1/responses, DeepSeek V3 with
reasoning.effort{"model":"bedrock-deepseek-v3","input":"What is 17*23? Answer with just the number.","max_output_tokens":2048,"reasoning":{"effort":"high"}}HTTP 200 {"types":["reasoning","message"],"text":"391","out_tokens":94}/v1/chat/completions, DeepSeek V3.1 with
reasoning_effort<param>="reasoning_effort":"high", modelbedrock-deepseek-v31HTTP 200 {"content":"391","reasoning":"First, the question is to multiply 17 by 23. I need to give ","completion_tokens":370}(streaming printsRRRRRRRRRRC;thinkingnow 400s withUnsupportedParamsError ... ['thinking'], for model=deepseek.v3-v1:0;"low"returns 200 withreasoningnull)/v1/messages and /v1/responses, DeepSeek V3.1
/v1/messagesand/v1/responsesbodies as the V3 cases, modelbedrock-deepseek-v31HTTP 200 {"blocks":["text"],"text":"To calculate \\(17 \\times 23\\):\n\n\\[\n17 \\t","output_tokens":39}andHTTP 200 {"types":["reasoning","message"],"text":"391","out_tokens":203}/v1/chat/completions and /v1/messages, Claude control with
thinking<param>="thinking":{"type":"enabled","budget_tokens":1024}, modelbedrock-claudeHTTP 200 {"content":"391","reasoning":"391","completion_tokens":13}andHTTP 200 {"blocks":["thinking","text"],"text":"391","output_tokens":13}(unchanged)Other Bedrock reasoning models, before and after
Since 263c34f merges the staging fix for GPT-6 into this branch, the neighbouring reasoning paths were re-run on both trees with
"reasoning_effort":"low"and"max_tokens":2048. Both proxies for this block were booted the same way withLITELLM_LOCAL_MODEL_COST_MAP=True, because the hosted cost map does not listus.openai.gpt-6-astrayet and without it the model is routed to the invoke API on either treebedrock-gpt-oss: beforeHTTP 200 {"content":"391","reasoning":"Just compute. 17*23 = 391.","completion_tokens":22}, afterHTTP 200 {"content":"391","reasoning":"Just compute. 17*23 = 391.","completion_tokens":22}bedrock-nova2: beforeHTTP 200 {"content":"391","reasoning":"[REDACTED].","completion_tokens":247}, afterHTTP 200 {"content":"391","reasoning":"[REDACTED].","completion_tokens":261}bedrock-gpt6: beforeHTTP 400 "litellm.UnsupportedParamsError: bedrock does not support parameters: ['reasoning_effort'], for model=us.openai.gpt-6-astra..."(the merge base predates the staging fix), afterHTTP 200 {"content":"391","reasoning":"null","completion_tokens":5}bedrock-gpt6withthinking:HTTP 400 "litellm.UnsupportedParamsError: bedrock does not support parameters: ['thinking'], for model=us.openai.gpt-6-astra..."on both trees, which is what staging does todaybedrock-claudewithreasoning_effort: "low":HTTP 200 {"content":"391","reasoning":"null","completion_tokens":5}on both treesObservations from the run, none caused by this PR:
/v1/messageserrors namereasoning_effort, notthinking, after adapter translation/v1/messagesmaps a 1024 budget tolow, so V3 skips reasoningreasoning_effort: "high"max_tokens: 600can spend it all on reasoningdata:chunksthinkinganddrop_paramsanswers without reasoning, same as beforeType
🐛 Bug Fix
Caveats (if any)
Low
reasoning_effortis forwarded to DeepSeek V3 verbatim, a deliberate choiceminimalgets a Bedrock 400 namingnone,low,medium,high), so the gateway does not narrow ithighvalues tohighwas rejected: V3 and V3.1 only reason athigh, but overriding an explicit caller value would hide that/v1/messagesbudget-to-effort mapping (1024 tokens becomeslow) is shared by every non-Claude Bedrock model and is unchanged herethinkingnow fails client-side (or is dropped withdrop_params) where it used to return 200 with the block silently ignoredarn:deployment is still not introspectedthinkingas before; a foundation-model ARN that resolves to DeepSeek has the field dropped by the mapping step with a debug logthinkingblock, tracked in [Bug]: Bedrock Converse silently dropsreasoning_effortfor non-Anthropic/Nova2/GPT-OSS models (e.g. Qwen3 on Bedrock) #34105is_thinking_enabledis computed before the DeepSeek drop, which is unobservable today: V3 uses native structured outputs and R1 has notool_choicesupportFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/e5e483ac1ef148fa9c0348e314377e1d
Note
Medium Risk
Changes Bedrock Converse parameter routing for reasoning across DeepSeek variants; well-tested but touches shared
map_openai_params/ supported-params logic used by many models.Overview
Fixes Bedrock Converse handling so DeepSeek models no longer receive Anthropic-shaped
thinking/ mis-mappedreasoning_effortinadditionalModelRequestFields, which caused R1 AWS 400s and left V3 reasoning ineffective.Supported params: DeepSeek stops advertising
thinkingandoutput_config. R1 no longer advertisesreasoning_effort(client-sideUnsupportedParamsErrorinstead of opaque Bedrock errors). V3 advertisesreasoning_effortand passes it through raw (same path as gpt-oss), not via Anthropicthinkingmapping.Request mapping: New DeepSeek-specific guards in
map_openai_paramsdropthinkingfor all DeepSeek models and dropreasoning_effortfor R1 (with debug logs);_handle_reasoning_effort_parametertreats DeepSeek like gpt-oss for passthrough. Claude, Nova 2, gpt-oss, and inference-profile paths are covered by regression tests so only DeepSeek is affected.Reviewed by Cursor Bugbot for commit 263c34f. Bugbot is set up for automated code reviews on this repo. Configure here.