Skip to content

fix(anthropic)!: route pdf data URIs to document blocks and share the transform with Snowflake - #39977

Open
mateo-berri wants to merge 33 commits into
mainfrom
litellm_lit_6778_snowflake_shared_anthropic_pt
Open

mateo-berri wants to merge 33 commits into
mainfrom
litellm_lit_6778_snowflake_shared_anthropic_pt

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Original

TLDR

Problem this solves:

  • PDF and text files in image_url blocks 400 on Claude
  • Replayed native tool_use blocks are dropped, so tool results 400

How it solves it:

  • PDF and text files go out as document blocks, and PDF bytes always do
  • Answered native tool_use blocks pass through, modify_params included
  • Snowflake uses the shared code
  • drop_params sends {} for non-object tool input

Intentional product change: without drop_params, Snowflake now 400s on input it cannot translate

Full TLDR

Problem this solves:

  • A PDF data URI inside an image_url block is sent as an image and rejected
  • That hits anthropic, bedrock invoke, and vertex Claude alike
  • A PDF linked by URL in an image_url block is downloaded for bedrock invoke and vertex and sent as an image, so it is rejected too
  • The same PDF as an input_image on /v1/responses fails the same way, and so does /utils/token_counter
  • A text/plain data URI, as a file block or an image_url block, is sent as a base64 document and rejected
  • A PDF whose data URI says application/octet-stream, carries a name= parameter, or whose format names an image type is still sent as an image or rejected
  • Snowflake Cortex kept its own copy of the Anthropic message translation, and it ignored drop_params
  • Already-parsed tool arguments crashed the shared translation, and dict, number, and boolean tool output was sent empty
  • An assistant turn whose content list holds a native tool_use block loses it, and the tool result that follows is rejected
  • The same turn is rejected again when the tool_use id holds characters Anthropic does not allow, because only the tool result side of the pair is cleaned up
  • With modify_params on, a replayed native tool_use answered by a tool message loses that result, and the request is rejected

How it solves it:

  • The shared transform now emits document blocks for PDF and text data URIs, with text/plain sent as a text source since Anthropic's base64 source only takes PDFs, decoded with the charset its data URI names when that is a standard text encoding
  • PDF bytes are recognized by their %PDF- signature, so a PDF goes out as a PDF document whatever its data URI or format says, and media type parameters like name= are stripped from document blocks
  • The format field on an image_url or file block otherwise decides whether the attachment is a document and what media type it is sent under
  • A PDF downloaded from an image_url link goes out as a document block on every dialect that downloads links, whatever its format says, and on anthropic an https:// link whose format says application/pdf goes out as a URL document block
  • New requires_inline_base64_media helper names the base64-only dialects, and the Snowflake config asks the shared transform for inline base64 itself
  • Snowflake delegates system and message translation to the shared Anthropic code and passes drop_params through to it, keeping only the text parts of a system prompt as before. A cache_control mark on a string system message now reaches Cortex the way it reaches every other Claude route, where the base dropped it on Snowflake alone while sending the same marked block for system content lists. The alternative was dropping it on Snowflake only. test_responses_bridge_message_cache_control_wire.py now expects the mark on its Snowflake string system row
  • A user part the shared code cannot translate, like input_audio, is a 400 on Snowflake naming the part, or dropped under drop_params. The base passed it to Cortex untranslated
  • Dict tool arguments are serialized instead of crashing, and dict, number, and boolean tool results go out as JSON text instead of empty. A null or missing tool result goes out as an empty string on every route. At the base, the SDK sent an empty string on the Claude routes and null on Snowflake, and through the proxy, which drops the null key, the Claude routes answered 400. The alternative was null on every route
  • A text attachment's charset must name a WHATWG Encoding Standard encoding, ASCII, or Latin-1 under a label Python knows, and any other is a 400 naming it. The alternatives were any Python codec, where a 700 KB charset=punycode attachment held the event loop for seconds, or a WHATWG label table, a new dependency for labels like x-cp1252
  • On the Claude routes, a 400 the shared translation raises on purpose, like that charset one, no longer pastes every message into its error text. Other translation errors still do, as at the base. The alternative was keeping the echo, where the punycode attachment's 400 took 42.8 s through the proxy while redacting its own copy of the request
  • tool_calls arguments that are not valid JSON, and native tool_use input that is not a JSON object, are a 400 naming the tool, or {} under drop_params. The alternatives were a 400 even under drop_params, or dropping the whole tool call, which would orphan its tool result
  • Native tool_use blocks in an assistant content list go through the shared transform, deduped against tool_calls that repeat the same id, with ids run through the same sanitizer as their tool results
  • modify_params pairs tool messages with native tool_use ids as well as tool_calls ids
  • A native tool_use block that no later tool result answers is dropped, as at the base, since Anthropic rejects a tool_use with no result. The alternatives were the 400 a tool_calls entry gets in that spot, or a modify_params style repair that invents a result
  • /utils/token_counter sends a PDF image_url as a document block like the chat request, a downloaded link included
  • PDF and text media types match in any letter case, and a malformed Snowflake user part is a 400 naming it, where the base forwarded it
  • A text attachment whose data URI names an encoding that does not exist is a 400 naming that encoding, not a 500
  • An image_url or file block whose format is not a string is handled as if format were absent, so the attachment is typed from its URL and bytes. The alternative was a 400 naming format, which the base never sent
  • On anthropic, azure_ai, and Bedrock Mantle, a token count litellm rejects before calling the provider, like a text attachment with an unknown charset or an image link it cannot download, is a 400 that the token_count_framing estimate does not replace, the same way a chat count translation error already answers
  • A downloaded text file is read as utf-8, since main's fix(anthropic): send PDF image_url content to Claude as document blocks #46984 drops the charset its server names, so another encoding answers a 400 that points at a file block's format, which takes text/plain;charset=.... The alternatives were re-encoding at fetch, which corrupted binaries a server labels as text, and keeping ;charset= in the data URI, which Gemini would forward as its mime type

User Flow

Before: a developer sends a PDF data URI in an image_url block to Claude and gets a 400

  1. They send POST https://litellm-domain/v1/chat/completions with a PDF data URI in image_url
  2. Anthropic, bedrock invoke, and vertex return HTTP 400 with an image media_type error
  3. Linked PDFs, text attachments, and replayed tool_use turns get HTTP 400 too

After: the same requests are answered from the attachment

  1. They send the same POST https://litellm-domain/v1/chat/completions
  2. It is HTTP 200, answered from the document
  3. /v1/responses, text attachments, replays, and linked PDFs return HTTP 200 too
Full user flow

Before: a developer sends a PDF as a data URI in an image_url block to a Claude model and gets a 400 back

  1. They send POST https://litellm-domain/v1/chat/completions to a Claude deployment on anthropic, bedrock invoke, or vertex, with a user message holding a text block plus an image_url block whose url is data:application/pdf;base64,...
  2. The response is HTTP 400 with media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'
  3. The same PDF sent as a file block, or as an image_url block inside a tool result, is answered normally, so only the plain user-content route is broken. A data:text/plain;base64,... attachment is HTTP 400 on both routes as well, with the same image error on the image_url route and document.source.base64.media_type: Input should be 'application/pdf' on the file route
  4. On a Snowflake Cortex Claude deployment, a tool call whose arguments are not valid JSON is forwarded to Cortex with an empty tool input, with or without "drop_params": true
  5. Replaying a stored Anthropic-format conversation, where the assistant turn's content list holds a tool_use block and the next message is that tool's result, is HTTP 400 with unexpected `tool_use_id` found in `tool_result` blocks on anthropic, bedrock invoke, and vertex alike
  6. Replaying that same conversation with a tool_use id like functions.Bash:0 gets the same 400, this time naming functions_Bash_0, because the tool result id is cleaned up and the id on the tool_use block is not
  7. A PDF sent as data:application/octet-stream;base64,... in an image_url block, with or without "format": "application/pdf", is HTTP 400 with the same image media_type error, and bedrock invoke answers the same way
  8. On a Snowflake Cortex Claude deployment, a text attachment whose data URI says charset=not-a-charset is forwarded to Cortex as is
  9. A latin-1 text attachment sent as data:text/plain;charset=iso-8859-1;base64,... in an image_url block, with "format": "text/plain" naming what it is, is HTTP 400 with the same image media_type error every text attachment gets
  10. Replaying that stored conversation when the tool_use block's input is a JSON string rather than an object gets the same 400, because the block is dropped either way
  11. When that input is the string "[1, 2]", the replay is the same 400, with or without "drop_params": true
  12. A PDF whose data URI carries a file name, data:application/pdf;name=invoice.pdf;base64,..., is HTTP 400 as an image_url block with the image media_type error, and as a file block with media_type: Input should be 'application/pdf'
  13. POST https://litellm-domain/utils/token_counter?call_endpoint=true with the step 1 messages is HTTP 400 with the same image media_type error
  14. On anthropic, a tool call whose arguments are not valid JSON is HTTP 400 naming the tool even with "drop_params": true
  15. On bedrock invoke and vertex, a PDF linked by https:// URL in an image_url block is HTTP 400 with the same image media_type error, and on anthropic the same link with "format": "application/pdf" is HTTP 400 with The file format is invalid or unsupported
  16. On anthropic, with modify_params: true in the proxy config, the step 5 replay is HTTP 400 with This model does not support assistant message prefill
  17. On a Snowflake Cortex Claude deployment, a user message holding an input_audio part is forwarded to Cortex with the input_audio part untranslated, with or without "drop_params": true
  18. /utils/token_counter?call_endpoint=true with the step 15 anthropic link, with or without its format, is HTTP 400 with the same image media_type error
  19. On anthropic, a link whose format is Application/PDF is HTTP 400 with The file format is invalid or unsupported, and a data:TEXT/PLAIN;base64,... attachment, as an image_url or file block, or an octet-stream one whose format is Text/Plain, is HTTP 400 with a media_type error
  20. On bedrock invoke, a PDF link whose format says image/png is HTTP 400 with Could not process image

After: the same request is answered from the PDF's contents

  1. They send the same POST https://litellm-domain/v1/chat/completions
  2. The response is HTTP 200 and the assistant answers from the document
  3. The file block and tool-result routes answer the same way as before, POST https://litellm-domain/v1/responses with the PDF as an input_image item is answered too, and the text/plain attachment is answered from its contents on both routes
  4. On a Snowflake Cortex Claude deployment, the same tool call comes back as HTTP 400 naming the tool, the same answer the other Claude providers give, and with "drop_params": true it is forwarded with an empty tool input as before
  5. The same replayed conversation is HTTP 200 and the assistant answers from the tool result
  6. The replay with a tool_use id like functions.Bash:0 is HTTP 200 as well, since both sides of the pair get the same cleanup
  7. The octet-stream PDF is HTTP 200 and answered from the document on both providers, with or without the format, since the bytes themselves are a PDF
  8. The Snowflake attachment with charset=not-a-charset comes back as HTTP 400 naming the encoding litellm could not find, and an attachment with a real charset is forwarded as before
  9. The latin-1 attachment is HTTP 200 and answered from its contents, because the charset its data URI declares survives the format the caller named
  10. The replay whose tool_use input is a JSON string is HTTP 200 as well, since the string is parsed into the object the API expects
  11. The "[1, 2]" replay is HTTP 400 saying the tool's input must be a JSON object and naming drop_params, and with "drop_params": true it is HTTP 200 with an empty input in its place
  12. The named PDF is HTTP 200 and answered from the document on both routes
  13. The token counter is HTTP 200 with the provider's token count
  14. With "drop_params": true that tool call is HTTP 200 and the assistant answers from the tool result
  15. The linked PDF is HTTP 200 and answered from the document on bedrock invoke and vertex, and on anthropic when the block's format says application/pdf. Without a format, an anthropic link still goes out as an image
  16. The modify_params replay is HTTP 200 and the assistant answers from the tool result
  17. The Snowflake input_audio message is HTTP 400 naming input_audio, and with "drop_params": true it is forwarded without that part
  18. The token counter is HTTP 200 with the provider's count for that link, with or without a format
  19. All of them are HTTP 200 and answered from the attachment
  20. The bedrock invoke link is HTTP 200 and answered from the document, since the downloaded bytes are a PDF

Relevant issues

Follow-up to #39453

Linear ticket

Resolves LIT-6778

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

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

Last updated: 21d08c8. QA ran on dfcfa0b, and R22 to R26 on the commits their steps name, against merge base 02ef44c. Changes since QA: the commits the /live-pr-risk summaries list and three main merges. Proof remains valid because no earlier case sends those inputs and R16e keeps its 400. Verification: unit tests and make check pass at 21d08c8

Case Before After
Legs 1, 4 on all four models 400 PINEAPPLE
Streaming leg 1 400 PINEAPPLE
R4, R5 dict tool data 400, ignored answered
R22 number, boolean tool results NONE 7316, false
R23 null tool result 400 NONE
R23 punycode text provider error local 400
R24 blank text beside tool_use 400 Sunny
R7, R14, R21d, R21f-h, R23, R26 text attachments 400 answered
R8 pdf with cache_control 400 PINEAPPLE
R10, R15, R19b tool_use replays 400 answered
R11, R16a, R17c-f, R18d-e relabeled pdf 400 PINEAPPLE
R16e non-utf-8 text image 400 encoding 400
R17g array tool_use input 400 400 naming it
R17h, R17i, R18f drop_params 400 answered
R17j, R21b-c token counter 400 counted
R19a, R20a, R21a, R21i linked pdf 400 answered
S1, S3, R20b, R21e Snowflake bad input forwarded 400
All controls same same
Shared setup

Both legs ran the same way on one box: a fresh worktree at the commit named in the heading, make bootstrap, the same .env, then python litellm/proxy/proxy_cli.py --config config.yaml --port <port> --num_workers 2, one proxy per leg with no database. The change is a per-request translation with no state held in a worker, so one instance per leg covers it. R19b runs on a second proxy per leg, booted the same way from config-modify.yaml, which is config.yaml plus litellm_settings: modify_params: true. anthropic uses ANTHROPIC_API_KEY, bedrock invoke uses AWS credentials in us-east-1, and vertex uses service-account credentials. secret.pdf.b64 is a one-page PDF whose only text is "The secret code word is PINEAPPLE." and the text attachments read "The secret code word is MANGO." Every call goes through the proxy to the real provider. The one exception is the snowflake-stub deployment, whose api_base is a closed local port and whose key is a placeholder, so nothing reaches Cortex and the S cases only show litellm's own handling before the network call

The config, every curl script, both test files, and the raw output of both legs are in this gist. Each script takes the proxy port and reads the proxy key from QA_KEY

Before (2e5cc9e)

anthropic legs 1-4

  1. zsh qa.sh 21893 anthropic-sonnet
Output
== leg 1 (anthropic-sonnet): /chat/completions, pdf data URI inside an image_url block in user content
{"content":null,"error":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64.media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'\"},\"request_id\":\"req_011CgXDBj3DcLue2TvvkWRMm\"}\n\nLiteLLM: model group 'anthropic-sonnet' failed with the error above. No fallback was attempted."}
== leg 2 (anthropic-sonnet): /chat/completions, same pdf data URI as a file block (control: the file route)
{"content":"PINEAPPLE","error":null}
== leg 3 (anthropic-sonnet): /chat/completions, same pdf data URI as an image_url block inside a tool result (control: the tool-result route)
{"content":"PINEAPPLE","error":null}
== leg 4 (anthropic-sonnet): /v1/responses, same pdf data URI as an input_image item
{"text":[],"error":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64.media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'\"},\"request_id\":\"req_011CgXDCMqYFkLRjbBNzLLXu\"}\n\nLiteLLM: model group 'anthropic-sonnet' failed with the error above. No fallback was attempted."}

bedrock invoke legs 1-4

Steps and output

bedrock/invoke/us.anthropic.claude-sonnet-5-5, /chat/completions legs 1-3 and /v1/responses leg 4

  1. zsh qa.sh 21893 bedrock-invoke-sonnet
== leg 1 (bedrock-invoke-sonnet): /chat/completions, pdf data URI inside an image_url block in user content
{"content":null,"error":"litellm.BadRequestError: BedrockException - {\"message\":\"messages.0.content.1.image.source.base64.media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'\"}\n\nLiteLLM: model group 'bedrock-invoke-sonnet' failed with the error above. No fallback was attempted."}
== leg 2 (bedrock-invoke-sonnet): /chat/completions, same pdf data URI as a file block (control: the file route)
{"content":"PINEAPPLE","error":null}
== leg 3 (bedrock-invoke-sonnet): /chat/completions, same pdf data URI as an image_url block inside a tool result (control: the tool-result route)
{"content":"PINEAPPLE","error":null}
== leg 4 (bedrock-invoke-sonnet): /v1/responses, same pdf data URI as an input_image item
{"text":[],"error":"litellm.BadRequestError: BedrockException - {\"message\":\"messages.0.content.1.image.source.base64.media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'\"}\n\nLiteLLM: model group 'bedrock-invoke-sonnet' failed with the error above. No fallback was attempted."}

vertex Sonnet 5.5 legs 1-4

Steps and output

vertex_ai/claude-sonnet-5-5, legs 1-3 and leg 4

  1. zsh qa.sh 21893 vertex-sonnet
== leg 1 (vertex-sonnet): /chat/completions, pdf data URI inside an image_url block in user content
{"content":null,"error":"litellm.BadRequestError: Vertex_aiException BadRequestError - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64.media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'\"},\"request_id\":\"req_vrtx_011CgXDD7mEqVAt78VUApwx2\"}\n\nLiteLLM: model group 'vertex-sonnet' failed with the error above. No fallback was attempted."}
== leg 2 (vertex-sonnet): /chat/completions, same pdf data URI as a file block (control: the file route)
{"content":"PINEAPPLE","error":null}
== leg 3 (vertex-sonnet): /chat/completions, same pdf data URI as an image_url block inside a tool result (control: the tool-result route)
{"content":"PINEAPPLE","error":null}
== leg 4 (vertex-sonnet): /v1/responses, same pdf data URI as an input_image item
{"text":[],"error":"litellm.BadRequestError: Vertex_aiException BadRequestError - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64.media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'\"},\"request_id\":\"req_vrtx_011CgXDDaqfE4UBzYw7DjfoQ\"}\n\nLiteLLM: model group 'vertex-sonnet' failed with the error above. No fallback was attempted."}

vertex Sonnet 4.6 legs 1-4

Steps and output

vertex_ai/claude-sonnet-4-6, legs 1-3 and leg 4

  1. zsh qa.sh 21893 vertex-sonnet-46
== leg 1 (vertex-sonnet-46): /chat/completions, pdf data URI inside an image_url block in user content
{"content":null,"error":"litellm.BadRequestError: Vertex_aiException BadRequestError - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64.media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'\"},\"request_id\":\"req_vrtx_011CgXDDffPF2Xq7fP4dJc5y\"}\n\nLiteLLM: model group 'vertex-sonnet-46' failed with the error above. No fallback was attempted."}
== leg 2 (vertex-sonnet-46): /chat/completions, same pdf data URI as a file block (control: the file route)
{"content":"The secret code word is **PINEAPPLE**.","error":null}
== leg 3 (vertex-sonnet-46): /chat/completions, same pdf data URI as an image_url block inside a tool result (control: the tool-result route)
{"content":"The secret code word is **PINEAPPLE**.","error":null}
== leg 4 (vertex-sonnet-46): /v1/responses, same pdf data URI as an input_image item
{"text":[],"error":"litellm.BadRequestError: Vertex_aiException BadRequestError - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64.media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'\"},\"request_id\":\"req_vrtx_011CgXDDymYy7WgiHGnG3mBd\"}\n\nLiteLLM: model group 'vertex-sonnet-46' failed with the error above. No fallback was attempted."}

Streaming leg 1

Steps and output

Leg 1 with "stream": true on anthropic and vertex

  1. zsh stream.sh 21893
== ST (anthropic-sonnet): /chat/completions with stream true, pdf data URI inside an image_url block
HTTP 400 litellm.BadRequestError: AnthropicException - b'{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.1.image.source.base64.media_type: Input should be \'image/jpeg\', \'image/png\', \'image/gif\' or \'image/webp\'"},"request_id":"req_011CgXDE2xnk6AJBxzY4xGiB"}'

LiteLLM: model group 'anthropic-sonnet' failed with the error above. No fallback was attempted.
== ST (vertex-sonnet): /chat/completions with stream true, pdf data URI inside an image_url block
HTTP 400 litellm.BadRequestError: Vertex_aiException BadRequestError - b'{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.1.image.source.base64.media_type: Input should be \'image/jpeg\', \'image/png\', \'image/gif\' or \'image/webp\'"},"request_id":"req_vrtx_011CgXDE7JEoHDQhJ9qwpVMy"}'

LiteLLM: model group 'vertex-sonnet' failed with the error above. No fallback was a

risk.sh to snow3.sh

The dependent-path scripts and their output at 2e5cc9e are in this gist

After (dfcfa0b)

anthropic legs 1-4

  1. zsh qa.sh 23417 anthropic-sonnet
== leg 1 (anthropic-sonnet): /chat/completions, pdf data URI inside an image_url block in user content
{"content":"PINEAPPLE","error":null}
== leg 2 (anthropic-sonnet): /chat/completions, same pdf data URI as a file block (control: the file route)
{"content":"PINEAPPLE","error":null}
== leg 3 (anthropic-sonnet): /chat/completions, same pdf data URI as an image_url block inside a tool result (control: the tool-result route)
{"content":"PINEAPPLE","error":null}
== leg 4 (anthropic-sonnet): /v1/responses, same pdf data URI as an input_image item
{"text":["PINEAPPLE"],"error":null}

bedrock invoke legs 1-4

Steps and output

bedrock/invoke/us.anthropic.claude-sonnet-5-5, /chat/completions legs 1-3 and /v1/responses leg 4

  1. zsh qa.sh 23417 bedrock-invoke-sonnet
== leg 1 (bedrock-invoke-sonnet): /chat/completions, pdf data URI inside an image_url block in user content
{"content":"PINEAPPLE","error":null}
== leg 2 (bedrock-invoke-sonnet): /chat/completions, same pdf data URI as a file block (control: the file route)
{"content":"PINEAPPLE","error":null}
== leg 3 (bedrock-invoke-sonnet): /chat/completions, same pdf data URI as an image_url block inside a tool result (control: the tool-result route)
{"content":"PINEAPPLE","error":null}
== leg 4 (bedrock-invoke-sonnet): /v1/responses, same pdf data URI as an input_image item
{"text":["PINEAPPLE"],"error":null}

vertex Sonnet 5.5 legs 1-4

Steps and output

vertex_ai/claude-sonnet-5-5, legs 1-3 and leg 4

  1. zsh qa.sh 23417 vertex-sonnet
== leg 1 (vertex-sonnet): /chat/completions, pdf data URI inside an image_url block in user content
{"content":"PINEAPPLE","error":null}
== leg 2 (vertex-sonnet): /chat/completions, same pdf data URI as a file block (control: the file route)
{"content":"PINEAPPLE","error":null}
== leg 3 (vertex-sonnet): /chat/completions, same pdf data URI as an image_url block inside a tool result (control: the tool-result route)
{"content":"PINEAPPLE","error":null}
== leg 4 (vertex-sonnet): /v1/responses, same pdf data URI as an input_image item
{"text":["PINEAPPLE"],"error":null}

vertex Sonnet 4.6 legs 1-4

Steps and output

vertex_ai/claude-sonnet-4-6, legs 1-3 and leg 4

  1. zsh qa.sh 23417 vertex-sonnet-46
== leg 1 (vertex-sonnet-46): /chat/completions, pdf data URI inside an image_url block in user content
{"content":"The secret code word is **PINEAPPLE**.","error":null}
== leg 2 (vertex-sonnet-46): /chat/completions, same pdf data URI as a file block (control: the file route)
{"content":"The secret code word is **PINEAPPLE**.","error":null}
== leg 3 (vertex-sonnet-46): /chat/completions, same pdf data URI as an image_url block inside a tool result (control: the tool-result route)
{"content":"The secret code word is **PINEAPPLE**.","error":null}
== leg 4 (vertex-sonnet-46): /v1/responses, same pdf data URI as an input_image item
{"text":["The secret code word is **PINEAPPLE**."],"error":null}

Streaming leg 1

Steps and output

Leg 1 with "stream": true on anthropic and vertex

  1. zsh stream.sh 23417
== ST (anthropic-sonnet): /chat/completions with stream true, pdf data URI inside an image_url block
HTTP 200 streamed: PINEAPPLE
== ST (vertex-sonnet): /chat/completions with stream true, pdf data URI inside an image_url block
HTTP 200 streamed: PINEAPPLE

risk.sh to snow3.sh

Eleven dependent-path scripts, steps and output

risk.sh

Steps and output

Dependent paths: tool calls, http image URLs, native /v1/messages, text/plain, cache_control, native tool_use

  1. zsh risk.sh 23417

The raw output is after-dfcfa0b043-risk.txt in the gist

risk10.sh

Steps and output

A dirty native tool_use id, and a pdf under a generic data URI mime with and without a format

  1. zsh risk10.sh 23417
== R10a (anthropic-sonnet): native tool_use block whose id carries characters anthropic rejects
{"content":"Sunny, twenty-two degrees.","tool":null,"error":null}
== R10b (bedrock-invoke-sonnet): same conversation on a second provider that shares the transform
{"content":"Sunny, twenty-two Celsius.","tool":null,"error":null}
== R11a (anthropic-sonnet): pdf sent under a generic data URI mime, with format saying application/pdf
{"content":"PINEAPPLE","tool":null,"error":null}
== R11b (anthropic-sonnet): the same generic data URI with no format (control: nothing declares it a pdf)
{"content":"PINEAPPLE","tool":null,"error":null}

risk14.sh

Steps and output

A charset-tagged text attachment, and a native tool_use block whose input is a JSON string

  1. zsh risk14.sh 23417
== R14a (anthropic-sonnet): latin-1 text attachment whose data URI names its charset, with an explicit matching format
{"content":"The secret code word is **MANGO**.","error":null}
== R14b (bedrock-invoke-sonnet): the same latin-1 attachment on a second provider
{"content":"MANGO","error":null}
== R14c (anthropic-sonnet): control, the same attachment with no format field so nothing overrides the data URI
{"content":"MANGO","error":null}
== R15a (anthropic-sonnet): assistant turn holding a native tool_use block whose input is a JSON string
{"content":"Sunny, twenty-two degrees.","error":null}
== R15b (bedrock-invoke-sonnet): the same conversation on a second provider
{"content":"Sunny, twenty-two degrees.","error":null}

risk16.sh

Steps and output

A format Anthropic has no block for, a media type carrying a file name, and an undecodable attachment

  1. zsh risk16.sh 23417
== R16a (anthropic-sonnet): a pdf data URI whose format says application/octet-stream
{"content":"PINEAPPLE","error":null}
== R16b (bedrock-invoke-sonnet): the same pdf on a second provider that shares the transform
{"content":"PINEAPPLE","error":null}
== R16c (anthropic-sonnet): a png data URI whose media type carries the file name, with a matching format
{"content":"Red.","error":null}
== R16d (bedrock-invoke-sonnet): the same png on a second provider that shares the transform
{"content":"Red","error":null}
== R16e (anthropic-sonnet): a text attachment whose bytes are not utf-8 and whose data URI names no charset
{"content":null,"error":"litellm.BadRequestError: AnthropicException - litellm.BadRequestError: Text attachment could not be read as 'utf-8': 'utf-8' codec can't decode byte 0xe9 in position 34: invalid continuation byte. Send it as utf-8, or name its encoding in the data URI (data:text/plain;charset=...).\nReceived Messages=[{'role': 'user', 'content': [{'type': 'text', 'text': 'What is the secret code word? One word.'}, {'type': 'image_url', 'image_url': {'url': 'data:text/plain;base64,VGhlIHNlY3JldCBjb2RlIHdvcmQgaXMgTUFOR08uIENhZukgYXUgbGFpdC4=', 'format': 'text/plain'}}]}]\n\nLiteLLM: model group 'anthropic-sonnet' failed with the error above. No fallback was attempted."}
== R16f (anthropic-sonnet): the same octet-stream pdf carried back inside a tool result
{"content":"PINEAPPLE","finish":"stop","error":null}

risk17.sh

Steps and output

An unanswered native tool_use, pdf bytes under other labels, a named pdf, non-object tool input, drop_params, and token counting

  1. zsh risk17.sh 23417

The raw output is after-dfcfa0b043-risk17.txt in the gist

risk18.sh

Steps and output

A native tool_use beside a tool_calls entry, gemini text format, pdf bytes under other labels, and non-object tool_calls arguments

  1. zsh risk18.sh 23417
== R18b (anthropic-sonnet): native tool_use with input "[1, 2]" beside a valid tool_calls entry with the same id
{"content":"The weather in Paris right now is sunny and 22°C (about 72°F).","finish":"stop","error":null}
== R18c (gemini-flash): text/plain;charset=utf-8 data URI with format text/plain
{"content":"MANGO","finish":"stop","error":null}
== R18c (vertex-gemini-flash): text/plain;charset=utf-8 data URI with format text/plain
{"content":"MANGO","finish":"stop","error":null}
== R18d (anthropic-sonnet): pdf bytes in a file block under data:application/octet-stream
{"content":"PINEAPPLE","finish":"stop","error":null}
== R18e (anthropic-sonnet): pdf data URI as an image_url block with format text/plain
{"content":"PINEAPPLE","finish":"stop","error":null}
== R18f (anthropic-sonnet): tool_calls arguments "[1, 2]" with drop_params true
{"content":"It's sunny in Paris right now, and the temperature is 22°C (about 72°F).","finish":"stop","error":null}

risk19.sh

Steps and output

A pdf linked by https URL on vertex and bedrock invoke, and a native tool_use answered by a tool message on a second proxy whose config sets modify_params: true

  1. zsh risk19.sh 23417 27731
== R19a (vertex-sonnet): image_url block whose url is an https pdf
{"content":"Dummy PDF file","finish":"stop","error":null}
== R19a (bedrock-invoke-sonnet): image_url block whose url is an https pdf
{"content":"Dummy PDF file","finish":"stop","error":null}
== R19b (anthropic-sonnet, proxy with modify_params true): native tool_use answered by a tool message
{"content":"The weather in Paris right now is sunny and 22°C (about 72°F).","finish":"stop","error":null}

risk20.sh

Steps and output

An https pdf link whose format says application/pdf on anthropic, and a user part Cortex Claude cannot take on the Snowflake stub, with and without drop_params

  1. zsh risk20.sh 23417
== R20a (anthropic-sonnet): https pdf link in an image_url block with format application/pdf
{"content":"Dummy PDF file","finish":"stop","error":null}
== R20b (snowflake-stub): user message holding an input_audio part
{"status":"400","message":"litellm.BadRequestError: SnowflakeException - Snowflake Cortex Claude cannot take input_audio parts in a user message. Remove them, or pass drop_params=True to drop them\n\nLiteLLM: model group 'snowflake-stub' failed with the error above. No fallback was attempted."}
== R20c (snowflake-stub): the same message with drop_params true (control: litellm accepts it and tries to reach Cortex)
{"status":"500","message":"litellm.APIConnectionError: SnowflakeException - Cannot connect to host REDACTED:9 ssl:<ssl.SSLContext object at 0x7cd8310d26d0> [Connect call failed ('REDACTED', 9)]\n\nLiteLLM: model group 'snowflake-stub' failed with the error above. No fallback was attempted."}

risk21.sh

Steps and output

On anthropic, an Application/PDF link and data:TEXT/PLAIN attachments in utf-8 and latin-1 as image_url and file blocks, plus an octet-stream text attachment whose format is Text/Plain. /utils/token_counter on an https pdf link with and without a format, a bedrock invoke pdf link whose format says image/png, and an image_url with no url on the Snowflake stub

  1. zsh risk21.sh 23417
== R21a (anthropic-sonnet): https pdf link whose format is Application/PDF in mixed case
{"content":"Dummy PDF file","error":null}
== R21b (anthropic-sonnet): /utils/token_counter?call_endpoint=true for the R20a request (https pdf link, format application/pdf)
{"total_tokens":1635,"count_source":"provider","error":null}
== R21c (anthropic-sonnet): /utils/token_counter?call_endpoint=true for the same link with no format
{"total_tokens":1635,"count_source":"provider","error":null}
== R21d (anthropic-sonnet): text attachment as an image_url whose data URI says TEXT/PLAIN
{"content":"MANGO","error":null}
== R21e (snowflake-stub): image_url block with no url
{"status":"400","message":"litellm.BadRequestError: SnowflakeException - 'url'\n\nLiteLLM: model group 'snowflake-stub' failed with the error above. No fallback was attempted."}
== R21f (anthropic-sonnet): latin-1 text attachment whose data URI says TEXT/PLAIN;charset=iso-8859-1
{"content":"CAFÉ","error":null}
== R21g (anthropic-sonnet): text attachment as a file block whose data URI says TEXT/PLAIN
{"content":"MANGO","error":null}
== R21h (anthropic-sonnet): text attachment sent as application/octet-stream with format Text/Plain
{"content":"MANGO","error":null}
== R21i (bedrock-invoke-sonnet): https pdf link whose format says image/png
{"content":"Dummy PDF file","error":null}

snow.sh

Steps and output

Snowflake Cortex tool call with broken JSON arguments

  1. zsh snow.sh 23417
== S1 (snowflake-stub): tool call whose arguments are not valid JSON
{"status":"400","message":"litellm.BadRequestError: SnowflakeException - Failed to parse tool call arguments for tool 'get_weather' (Anthropic tool invoke). Error: Expecting property name enclosed in double quotes: line 1 column 2 (char 1). Arguments: {not json\n\nLiteLLM: model group 'snowflake-stub' failed with the error above. No fallback was attempted."}
== S2 (snowflake-stub): the same conversation with valid tool-call JSON (control: litellm accepts it and tries to reach Cortex)
{"status":"500","message":"litellm.APIConnectionError: SnowflakeException - Cannot connect to host REDACTED:9 ssl:<ssl.SSLContext object at 0x7deb1d6ea6d0> [Connect call failed ('REDACTED', 9)]\n\nLiteLLM: model group 'snowflake-stub' failed with the error above. No fallback was attempted."}

snow3.sh

Steps and output

Snowflake Cortex text attachment with an unknown charset

  1. zsh snow3.sh 23417
== S3 (snowflake-stub): text attachment whose data URI names a charset that does not exist
{"status":"400","message":"litellm.BadRequestError: SnowflakeException - litellm.BadRequestError: Text attachment could not be read as 'not-a-charset': unknown encoding: not-a-charset. Send it as utf-8, or name its encoding in the data URI (data:text/plain;charset=...).\n\nLiteLLM: model group 'snowflake-stub' failed with the error above. No fallback was attempted."}
== S4 (snowflake-stub): the same attachment with a charset that exists (control: litellm accepts it and tries to reach Cortex)
{"status":"500","message":"litellm.APIConnectionError: SnowflakeException - Cannot connect to host REDACTED:9 ssl:<ssl.SSLContext object at 0x7deb1d6ea6d0> [Connect call failed ('REDACTED', 9)]\n\nLiteLLM: model group 'snowflake-stub' failed with the error above. No fallback was attempted."}

R22 number and boolean tool results

Steps and output, before 02ef44c, after 735ace4

A chat completion replays one tool call whose tool message content is the JSON number 7316 or the JSON boolean false, with the string "7316" as a control, on each Claude route. Both proxies ran 2 workers from the same config

  1. zsh risk22.sh <port>
#!/bin/zsh
# usage: ./risk22.sh <port>   a tool result that is a JSON number or boolean, on each Claude route, plus the same result as a string
P=$1
A=(-H "Authorization: Bearer $QA_KEY" -H 'Content-Type: application/json')
J='{content: .choices[0].message.content, error: .error.message}'
req() {
  print -r -- "{\"model\":\"$1\",\"max_tokens\":20,\"tools\":[{\"type\":\"function\",\"function\":{\"name\":\"$2\",\"description\":\"$3\",\"parameters\":{\"type\":\"object\",\"properties\":{}}}}],\"messages\":[{\"role\":\"user\",\"content\":\"$4 Use the tool. Reply with only the value the tool returned, or NONE if it returned nothing.\"},{\"role\":\"assistant\",\"content\":null,\"tool_calls\":[{\"id\":\"call_1\",\"type\":\"function\",\"function\":{\"name\":\"$2\",\"arguments\":\"{}\"}}]},{\"role\":\"tool\",\"tool_call_id\":\"call_1\",\"content\":$5}]}"
}
for M in anthropic-sonnet bedrock-invoke-sonnet vertex-sonnet; do
  echo "== R22 ($M): tool result is the JSON number 7316"
  curl -s -m 120 "http://localhost:$P/chat/completions" "${A[@]}" -d "$(req $M count_open_orders 'Returns how many orders are open' 'How many orders are open?' 7316)" | jq -c "$J"
  echo "== R22 ($M): tool result is the JSON boolean false"
  curl -s -m 120 "http://localhost:$P/chat/completions" "${A[@]}" -d "$(req $M is_store_open 'Returns whether the store is open' 'Is the store open?' false)" | jq -c "$J"
  echo "== R22 ($M): control, tool result is the string \"7316\""
  curl -s -m 120 "http://localhost:$P/chat/completions" "${A[@]}" -d "$(req $M count_open_orders 'Returns how many orders are open' 'How many orders are open?' '"7316"')" | jq -c "$J"
done

Before, at merge base 02ef44c

base tree HEAD 02ef44c388, 2 workers, port 20768
== R22 (anthropic-sonnet): tool result is the JSON number 7316
{"content":"NONE","error":null}
== R22 (anthropic-sonnet): tool result is the JSON boolean false
{"content":"NONE","error":null}
== R22 (anthropic-sonnet): control, tool result is the string "7316"
{"content":"7316","error":null}
== R22 (bedrock-invoke-sonnet): tool result is the JSON number 7316
{"content":"NONE","error":null}
== R22 (bedrock-invoke-sonnet): tool result is the JSON boolean false
{"content":"NONE","error":null}
== R22 (bedrock-invoke-sonnet): control, tool result is the string "7316"
{"content":"7316","error":null}
== R22 (vertex-sonnet): tool result is the JSON number 7316
{"content":"NONE","error":null}
== R22 (vertex-sonnet): tool result is the JSON boolean false
{"content":"NONE","error":null}
== R22 (vertex-sonnet): control, tool result is the string "7316"
{"content":"7316","error":null}

After, at 735ace4

head tree HEAD 735ace429b, 2 workers, port 23249
== R22 (anthropic-sonnet): tool result is the JSON number 7316
{"content":"7316","error":null}
== R22 (anthropic-sonnet): tool result is the JSON boolean false
{"content":"false","error":null}
== R22 (anthropic-sonnet): control, tool result is the string "7316"
{"content":"7316","error":null}
== R22 (bedrock-invoke-sonnet): tool result is the JSON number 7316
{"content":"7316","error":null}
== R22 (bedrock-invoke-sonnet): tool result is the JSON boolean false
{"content":"false","error":null}
== R22 (bedrock-invoke-sonnet): control, tool result is the string "7316"
{"content":"7316","error":null}
== R22 (vertex-sonnet): tool result is the JSON number 7316
{"content":"7316","error":null}
== R22 (vertex-sonnet): tool result is the JSON boolean false
{"content":"false","error":null}
== R22 (vertex-sonnet): control, tool result is the string "7316"
{"content":"7316","error":null}

R23 null tool results and text charsets

Steps and output, before 02ef44c, after fb753f0

A chat completion replays one tool call whose tool message content is null on each Claude route and Snowflake. Then a 699 KB text attachment whose data URI says charset=punycode, and a Shift JIS one whose data URI names it, go to Claude routes and Snowflake. The Snowflake deployment points at an account that does not exist, so a 404 or 502 means litellm forwarded the request. Both proxies ran 2 workers from the same config

  1. zsh risk23.sh <port>
#!/bin/zsh
# usage: ./risk23.sh <port>   a null tool result on each Claude route and Snowflake, then text attachments in punycode and Shift JIS
P=$1
A=(-H "Authorization: Bearer $QA_KEY" -H 'Content-Type: application/json')
J='{status: $s, content: .choices[0].message.content, error: (.error.message // null | if . then .[0:90] else . end)}'
call() {
  local out=$(mktemp)
  local code_time=$(curl -s -m 180 -o $out -w '%{http_code} %{time_total}' "http://localhost:$P/chat/completions" "${A[@]}" -d @-)
  jq -c --arg s "${code_time% *}" "$J" $out
  echo "time_total ${code_time#* }s"
  rm -f $out
}
tool_req() {
  print -r -- "{\"model\":\"$1\",\"max_tokens\":20,\"tools\":[{\"type\":\"function\",\"function\":{\"name\":\"lookup_value\",\"description\":\"Returns the value the user asked for\",\"parameters\":{\"type\":\"object\",\"properties\":{}}}}],\"messages\":[{\"role\":\"user\",\"content\":\"What value does the lookup return? Use the tool. Reply with only the value the tool returned, or NONE if it returned nothing.\"},{\"role\":\"assistant\",\"content\":null,\"tool_calls\":[{\"id\":\"call_1\",\"type\":\"function\",\"function\":{\"name\":\"lookup_value\",\"arguments\":\"{}\"}}]},{\"role\":\"tool\",\"tool_call_id\":\"call_1\",\"content\":null}]}"
}
file_req() {
  print -r -- "{\"model\":\"$1\",\"max_tokens\":20,\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"text\",\"text\":\"What is the secret word in this file? One word, or NONE.\"},{\"type\":\"file\",\"file\":{\"file_data\":\"data:text/plain;charset=$2;base64,$3\"}}]}]}"
}
for M in anthropic-sonnet bedrock-invoke-sonnet vertex-sonnet snowflake-real; do
  echo "== R23 ($M): the tool message content is null"
  tool_req $M | call
done
SJIS=$(print -rn -- '秘密の言葉は MANGO です。' | iconv -f utf-8 -t shift_jis | base64 | tr -d '\n')
PUNY=$(head -c 524288 /dev/zero | tr '\0' a | base64 | tr -d '\n')
for M in anthropic-sonnet snowflake-real; do
  echo "== R23 ($M): a 699 KB text attachment whose data URI says charset=punycode"
  file_req $M punycode $PUNY | call
done
for M in anthropic-sonnet bedrock-invoke-sonnet; do
  echo "== R23 ($M): a Shift JIS text attachment whose data URI says charset=shift_jis"
  file_req $M shift_jis $SJIS | call
done

Before, at merge base 02ef44c

base2 tree HEAD 02ef44c388, 2 workers, port 32297
== R23 (anthropic-sonnet): the tool message content is null
{"status":"400","content":null,"error":"litellm.BadRequestError: AnthropicException - 'content'\nReceived Messages=[{'role': 'user'"}
time_total 1.049862s
== R23 (bedrock-invoke-sonnet): the tool message content is null
{"status":"400","content":null,"error":"litellm.BadRequestError: BedrockException - 'content'\nReceived Messages=[{'role': 'user', "}
time_total 1.452312s
== R23 (vertex-sonnet): the tool message content is null
{"status":"400","content":null,"error":"litellm.BadRequestError: Vertex_aiException BadRequestError - 'content'\nReceived Messages="}
time_total 0.861920s
== R23 (snowflake-real): the tool message content is null
{"status":"404","content":null,"error":"litellm.NotFoundError: SnowflakeException - <!DOCTYPE html>\n<html lang=\"en-US\">\n<head>\n<ti"}
time_total 3.518718s
== R23 (anthropic-sonnet): a 699 KB text attachment whose data URI says charset=punycode
{"status":"400","content":null,"error":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_req"}
time_total 1.367769s
== R23 (snowflake-real): a 699 KB text attachment whose data URI says charset=punycode
{"status":"502","content":null,"error":"litellm.BadGatewayError: SnowflakeException - <html>\n<head>\n    <title>502 Bad Gateway</ti"}
time_total 11.089565s
== R23 (anthropic-sonnet): a Shift JIS text attachment whose data URI says charset=shift_jis
{"status":"400","content":null,"error":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_req"}
time_total 2.463036s
== R23 (bedrock-invoke-sonnet): a Shift JIS text attachment whose data URI says charset=shift_jis
{"status":"400","content":null,"error":"litellm.BadRequestError: BedrockException - {\"message\":\"messages.0.content.1.document.sour"}
time_total 2.297441s

After, at fb753f0

head3 tree HEAD fb753f003d, 2 workers, port 32072
== R23 (anthropic-sonnet): the tool message content is null
{"status":"200","content":"NONE","error":null}
time_total 0.815996s
== R23 (bedrock-invoke-sonnet): the tool message content is null
{"status":"200","content":"NONE","error":null}
time_total 0.802783s
== R23 (vertex-sonnet): the tool message content is null
{"status":"200","content":"NONE","error":null}
time_total 0.926925s
== R23 (snowflake-real): the tool message content is null
{"status":"404","content":null,"error":"litellm.NotFoundError: SnowflakeException - <!DOCTYPE html>\n<html lang=\"en-US\">\n<head>\n<ti"}
time_total 0.474603s
== R23 (anthropic-sonnet): a 699 KB text attachment whose data URI says charset=punycode
{"status":"400","content":null,"error":"litellm.BadRequestError: AnthropicException - litellm.BadRequestError: Text attachment cou"}
time_total 0.119329s
== R23 (snowflake-real): a 699 KB text attachment whose data URI says charset=punycode
{"status":"400","content":null,"error":"litellm.BadRequestError: SnowflakeException - litellm.BadRequestError: Text attachment cou"}
time_total 0.128710s
== R23 (anthropic-sonnet): a Shift JIS text attachment whose data URI says charset=shift_jis
{"status":"200","content":"MANGO","error":null}
time_total 1.116739s
== R23 (bedrock-invoke-sonnet): a Shift JIS text attachment whose data URI says charset=shift_jis
{"status":"200","content":"The secret word is **MANGO**.","error":null}
time_total 0.736296s

R24-R26 blank text beside tool_use, numeric role, charsets

Steps and output, before 02ef44c and 1fecc7a, after 4766510, 4681fbd, and 21d08c8

R24 replays a blank text part beside a native tool_use that the next tool message answers, on four Claude routes, plus one nobody answers, each proxy on 2 workers behind a recorder. At 02ef44c only the placeholder goes out and Claude answers 400. At 1fecc7a the placeholder goes out next to the tool_use, Bugbot's finding. At 4766510 the tool_use goes out alone. The unanswered one keeps the placeholder on every side. Main's later commits to these files leave both alone. R25 sends a third message with role 123 at 4681fbd, which answers main's 400 naming the field on all four routes. R26 sends text attachments labeled iso-8859-9, iso-8859-11, tis-620, gb2312, big5-hkscs, and ms932 on three of those routes, which answer 400 on both before trees and MANGO at 21d08c8, Bugbot's second finding

  1. zsh risk24.sh <port>
  2. zsh risk25.sh <port>
  3. zsh risk26.sh <port>

Scripts, client output, and the recorded assistant turns are in this gist

Observations from the run
  • vertex Sonnet 4.6 answers in sentences, the others one word
  • text/plain file route also 400s at base, all three providers
  • R5 at base answers as if the tool returned nothing
  • R22 at base answers NONE on all three Claude routes
  • R23 null tool result at base 400s on Claude routes
  • R23 punycode 400 took 42.8 s at 0e1546b
  • Claude refuses a prompt asking it to repeat itself
  • R8 wrote 1611 cache tokens on the pdf block
  • R11b generic mime with no format now answers, by design
  • R16e non-utf-8 text stays 400, now naming the encoding
  • Streaming error at base is a plain JSON 400, not SSE
  • Sonnet 5.5 can use 30 tokens before any text, both legs
  • Live Cortex leg not run, no Snowflake credentials reachable
  • CodSpeed red at ade0e42 was this PR, fixed at 6bdd0be
  • Native image, search_result, tool_result user parts fail validation at base
  • Before leg rerun at the new merge base 2e5cc9e, unchanged

Type

🐛 Bug Fix
🧹 Refactoring

Caveats (if any)

High

  • No live Snowflake Cortex proof, only a local stub

Medium

  • Without drop_params, Snowflake answers broken tool-call JSON and user parts it cannot translate with a 400

Low

  • osv-scan is red on main too
  • The text-decode 400 repeats its error prefix
  • Snowflake drops assistant images, which Anthropic rejects
  • A replayed tool_use loses its caller field
  • Anthropic still sends an https:// PDF link with no format as an image, LIT-9762
  • Colliding sanitized tool ids, name-paired function messages, and Snowflake lifting later system messages, as at the base
  • azure_ai and Bedrock Claude Platform are proven only through the anthropic translation they reuse
  • Non-utf-8 text answers 400 unless a file block's format names the charset, since image_url ignores it
  • Pre-call guardrails skip object tool arguments and native tool_use input, which Snowflake already forwarded and Claude routes now forward too

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
  • c0b2432 passes /live-pr-risk
  • fb753f0 passes /live-pr-risk
  • 4681fbd passes /live-pr-risk
  • 21d08c8 passes /live-pr-risk
/live-pr-risk at c0b2432

Verdict. Safe to ship, with one decision below on downloaded text that is not utf-8. Every earlier count, PDF, text and tool_result case re-ran base vs c0b2432 on real Anthropic, Azure AI Foundry Claude, Bedrock invoke and Mantle, Vertex Claude, Gemini and Vertex Gemini, plus new count, data URI and downloaded text cases. Each proxy ran 2 workers with a recorder in front of the provider, and c0b2432 merged into main matched every status

Breaking. Bedrock Mantle answered 500 at 3f3f9bd for a text attachment with an unknown charset. f18056a fixes it, and it is a local 400 again

Backward incompatible

  • A downloaded text file that is not utf-8 answers a local 400 naming the encoding, where the base answered the provider's image 400, since main's fix(anthropic): send PDF image_url content to Claude as document blocks #46984 drops the server's charset. Kept on purpose, because re-encoding at fetch corrupted binaries a server labels as text, and keeping the charset in the data URI would reach Gemini as its mime type. A file block that names the charset in format answers 200, and d0bb701 points the 400 at it
  • A token count litellm rejects before calling the provider is a 400 on every Claude counter, framing or not, where the base answered 500 or a framed estimate. litellm's convention that input it cannot translate is a 400 settles it (f18056a)
  • The bytes decide more data URI shapes, so real PDF bytes behind an odd label go from 400 to 200 (c0b2432), and PNG bytes labelled application/pdf get a different provider 400
  • A non-string format is ignored, which turns a 400 into 200, as the TLDR says (3f3f9bd)
  • Charset and base64 errors are local 400s with new messages (f18056a)
  • The dfcfa0b entries hold unchanged. They cover mixed-case file_id formats, the drop_params 400 for a non-object tool_use.input, a nameless native tool_use, placeholder text beside a native tool_use, dict tool results as JSON text, and Snowflake on the shared transform

Regression risk. Downloaded text on the count routes is counted as an image, so chat and count disagree, as at the base. The runtime-to-Mantle count fallback can flag a 400 as rejected before the provider call although bedrock-runtime was called, and nothing reads the flag there. Mantle chat, the Bedrock batch record, claude_platform and opencode_go have no deployment in the rig and are traced only

Not verified. Live Snowflake Cortex, since no credential exists. The SDK acount_tokens and count_prompt_tokens error paths, SSRF blocks and the image size cap on the count routes are traced only

/live-pr-risk at fb753f0

Verdict. Safe to ship, with one decision below on Snowflake system prompt cache marks. This run covers the commits since c0b2432. The rig ran merge base 02ef44c, 0e1546b, and fb753f0 side by side on real Anthropic, Azure AI Foundry Claude, Bedrock invoke, and Vertex Claude, plus a Snowflake host that does not exist, each proxy on 2 workers with a recorder in front of the provider. Every outbound request at fb753f0 matched 0e1546b, the branch with main merged in, and only error text and model wording changed

Breaking. Two showed up during the run, and both are fixed here. At 735ace4 a Snowflake tool message with no content answered a 400 naming 'content', where the base sent an empty tool result, and 0d18854 sends an empty string again. After Veria's finding, a 699 KB text attachment whose data URI says charset=punycode decoded for seconds on the event loop. 7d5bce3 decodes only standard text encodings, and fb753f0 keeps the request out of that 400, so it answers in 0.12 s where 0e1546b took 42.8 s

Backward incompatible

  • Number and boolean tool results go out as JSON text, where the base sent them empty (735ace4)
  • A null or missing tool result goes out as an empty string on every route, where the base answered 400 through the proxy on the Claude routes (0d18854)
  • A text attachment whose charset is not a standard text encoding is a local 400 naming it, where the base sent it to the provider and got the provider's 400. A Shift JIS attachment that names its charset answers 200 (7d5bce3)
  • A cache_control mark on a string system message now reaches Snowflake Cortex, where the base dropped it on Snowflake alone. The base already sent the same marked block to Cortex for system content lists, and Snowflake's prompt caching docs list system messages. Kept on purpose, so Snowflake matches every other Claude route, and test_responses_bridge_message_cache_control_wire.py now expects it (1fecc7a)
  • The deliberate translation 400s on the Claude routes no longer end with Received Messages=, and no test or caller reads that text (fb753f0)
  • The d0bb701 hint still points a downloaded non-utf-8 text 400 at a file block's format, and that format answers 200
  • The c0b2432 entries hold unchanged

Regression risk. Main's #49192 conflicted with this PR in the shared tool call conversion, and the merge keeps one convert_to_anthropic_tool_invoke call that passes drop_params. Unit tests and the rig pass on it. Pre-call guardrails still skip object tool arguments, a pre-existing gap that is filed. Other translation errors still carry the request in their 400 text, as at the base

Dependency graph. The new commits touch the shared tool result text, the text attachment decoder, and the Claude chat error path. Their callers are the anthropic, azure_ai, Bedrock invoke and Mantle, Vertex Claude, and Snowflake chat routes, /v1/messages, /v1/responses through the chat bridge, and the token counters. The rig drove each of them live except Mantle chat and Snowflake, and the count routes sent the same requests as 0e1546b. The old tests/llm_translation and tests/local_testing suites no longer exist, so tests/integration stood in for them. Its providers, security, sdk, extensions, and accounting groups passed at 0e1546b except the Snowflake string system cache row, which passes at 1fecc7a

Not verified. Live Snowflake Cortex, since no credential exists, so how Cortex answers a system prompt cache mark is unproven. Mantle chat, the Bedrock batch record, claude_platform, and opencode_go have no deployment in the rig and are traced only

/live-pr-risk at 4681fbd and 21d08c8

Verdict. Safe to ship. This run covers 488f3d2, the fix for Bugbot's placeholder finding, the third main merge 4766510, 4681fbd, which fixes a clash that merge caused, and 21d08c8, the fix for Bugbot's charset finding. R24 ran 02ef44c, 1fecc7a, and 4766510 side by side on real Anthropic, Bedrock invoke, Vertex Claude, and Azure AI Foundry Claude, each proxy on 2 workers behind a recorder. R25 and R23 ran at 4681fbd on the same routes, and R26 ran 02ef44c, 1fecc7a, and 21d08c8 on three of them

Breaking. Two showed up, and both are fixed here. At 1fecc7a a blank text part beside an answered native tool_use went out as the placeholder next to it, and 488f3d2 sends the tool_use alone. At 4766510 a numeric role answered "Invalid Message passed in" instead of main's #49237 400 naming the field, because this PR's handler for deliberate translation 400s ran first. 4681fbd names the role first, and R25 shows it on all four routes

Backward incompatible. Nothing new. The fb753f0 entries hold. A #49237 test that used object tool call arguments as a failing input now uses list arguments, since this PR accepts object arguments on purpose

Regression risk. An unanswered native tool_use still gets the placeholder, as R24's control shows. The role check returns nothing when every role is a string, so the R23 charset 400 keeps its message. The six codecs 21d08c8 adds are linear table codecs, and the unit tests show punycode and utf-7 still answer 400. Main's #49371 and #47692 changed the same files without touching empty text, roles, or tool_use replay

Dependency graph. The sanitizer's only callers are anthropic_messages_pt and the modify_params tool pairing, and the role check sits in the Anthropic chat transform. Their callers are the anthropic, azure_ai, Bedrock invoke and Mantle, Vertex Claude, and Snowflake chat routes, /v1/messages and /v1/responses through the chat bridge, and the token counters. The rig drove the four Claude chat routes, and the earlier cases passed again at 4766510. R24 did not run again at 4681fbd, since its roles are strings

Not verified. Live Snowflake Cortex, Mantle chat, /v1/responses, and the token counters for these cases, traced only, and R26 on Bedrock, whose rig credentials had expired

Bugbot summary

[!NOTE]
Medium Risk
Central Anthropic message translation changes affect every Claude route (Anthropic, Bedrock, Vertex, Snowflake) plus token counting, with intentional Snowflake behavior changes and new attachment decoding/error paths.

Overview
Fixes Claude 400s by routing PDF and text attachments (including image_url data URIs, tool results, and linked PDFs where applicable) through shared logic that emits document blocks, detects PDF bytes by signature, and decodes text/plain with charset-aware handling instead of base64 image/document mime errors.

Native tool_use replay is added to anthropic_messages_pt: answered blocks pass through with sanitized IDs matching tool results, deduping against tool_calls, optional drop_params coercion of invalid tool input to {}, and empty-text handling beside answered tool uses. parse_tool_call_arguments now accepts already-parsed mappings; tool results serialize dict/number/boolean/null content to JSON or empty string.

Snowflake Cortex Claude drops its bespoke message converter and calls anthropic_messages_pt (with force_base64), surfacing local 400s for untranslatable user parts and bad tool JSON unless drop_params is set. Count-token paths align with chat translation and return 400 for pre-provider validation errors without provider calls.

Tool-use ID sanitizers move to common_utils; deliberate BadRequestError responses no longer echo full message payloads on Anthropic chat failures.

Reviewed by Cursor Bugbot for commit 21d08c8. Bugbot is set up for automated code reviews on this repo. Configure here.

…ocks

A data:application/pdf or data:text/plain URI arriving as a plain image_url
block in user content was emitted as an Anthropic image block, which
anthropic, bedrock invoke, and vertex all reject with a media_type error.
The shared transform now routes those to document blocks the way tool
results already did, and requires_inline_base64_media names the dialects
that only accept inline base64 media, Snowflake included.

Snowflake Cortex Claude requests now go through translate_system_message
and anthropic_messages_pt instead of a private copy of the translation.
The shared path accepts already-parsed tool-call arguments and dict tool
results, and an unparseable tool-call JSON is a 400 SnowflakeException
rather than an empty tool input. Snowflake shape assertions follow the
shared transform: block-list user content and merged consecutive user turns.
@mateo-berri
mateo-berri requested a review from a team September 5, 2026 23:27
…itellm_lit_6778_snowflake_shared_anthropic_pt
@greptile-apps

greptile-apps Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest charset change appears safe to merge, with no new actionable findings

Summary

This PR sends PDF and text attachments as document blocks, preserves answered native tool_use blocks, and moves Snowflake onto the shared Anthropic translation

The latest change adds six text encodings and regression cases for their labels. No new actionable issues were found

Previously acknowledged items remain deferred. mateo-berri accepted sanitized tool ID collisions as separately tracked behavior matching the existing tool_calls path. mateo-berri also deferred live Snowflake proof because no Cortex credentials were reachable and said a human would review that caveat before merge

  • Claude routes send PDFs and plain-text attachments as documents.
  • Replayed Claude tool turns keep their answered tool calls and results.
  • Snowflake Cortex Claude uses the shared Claude message translator.

Reviews (25) · Last reviewed commit: "fix(anthropic): decode text attachments ..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 43 untouched benchmarks


Comparing litellm_lit_6778_snowflake_shared_anthropic_pt (21d08c8) with main (187f936)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (60fc121) during the generation of this report, so 187f936 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.56522% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...llm/litellm_core_utils/prompt_templates/factory.py 99.35% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

…e inline base64 from the Snowflake config

Anthropic's base64 document source only accepts application/pdf, so a
text/plain data URI (in a file block or in an image_url block) was built into
a document the API rejects with a 400. The shared file-block builder now
decodes text/plain into a `text` source, which every Anthropic-shaped
provider accepts.

The shared translator also no longer keeps a provider list for base64-only
dialects. Snowflake passes force_base64 into anthropic_messages_pt from its
own transformation, and requires_inline_base64_media keeps covering bedrock
invoke and vertex the way the inline check did before.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 5, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Parameterized text URIs skip text source
    • Normalized the media_type in anthropic_process_openai_file_message by stripping MIME parameters before the text/plain equality check so charset-qualified text/plain data URIs now route to the text source instead of the base64 document Anthropic rejects.

Create PR

Or push these changes by commenting:

@cursor push a23f4b5e90
Preview (a23f4b5e90)
diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py
--- a/litellm/litellm_core_utils/prompt_templates/factory.py
+++ b/litellm/litellm_core_utils/prompt_templates/factory.py
@@ -1904,7 +1904,8 @@
             openai_image_url=file_data,
             format=format,
         )
-        if image_chunk["media_type"] == "text/plain":
+        media_type: Final = image_chunk["media_type"].split(";", 1)[0].strip()
+        if media_type == "text/plain":
             return AnthropicMessagesDocumentParam(
                 type="document",
                 source=AnthropicContentParamSourceText(
@@ -1917,7 +1918,7 @@
             type="document",
             source=AnthropicContentParamSource(
                 type="base64",
-                media_type=image_chunk["media_type"],
+                media_type=media_type,
                 data=image_chunk["data"],
             ),
         )

diff --git a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py
--- a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py
+++ b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py
@@ -3559,6 +3559,9 @@
 
 
 _TEXT_DATA_URI = "data:text/plain;base64," + base64.b64encode("the secret code word is MANGO\n".encode()).decode()
+_TEXT_DATA_URI_WITH_CHARSET = (
+    "data:text/plain;charset=utf-8;base64," + base64.b64encode("the secret code word is MANGO\n".encode()).decode()
+)
 _TEXT_DOCUMENT_BLOCK = {
     "type": "document",
     "source": {"type": "text", "media_type": "text/plain", "data": "the secret code word is MANGO\n"},
@@ -3570,8 +3573,10 @@
     [
         {"type": "image_url", "image_url": {"url": _TEXT_DATA_URI}},
         {"type": "file", "file": {"file_data": _TEXT_DATA_URI}},
+        {"type": "image_url", "image_url": {"url": _TEXT_DATA_URI_WITH_CHARSET}},
+        {"type": "file", "file": {"file_data": _TEXT_DATA_URI_WITH_CHARSET}},
     ],
-    ids=["image_url", "file"],
+    ids=["image_url", "file", "image_url_with_charset", "file_with_charset"],
 )
 def test_anthropic_messages_pt_text_plain_data_uri_becomes_text_source_document(block):
     """

You can send follow-ups to the cloud agent here.

…rry a charset parameter

A data:text/plain;charset=utf-8;base64,... attachment passed the document
detection but reached the file-block builder with the parameter still in its
media type, so the text/plain comparison missed and the text went out as a
base64 document that Anthropic rejects with a 400. The builder now compares
the bare media type and decodes the bytes with the charset the URI names,
defaulting to utf-8.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

The shared transform only passed through server_tool_use and *_tool_result
blocks, so replaying a stored conversation whose assistant turn carries a
native tool_use block dropped the block and the tool_result that followed had
no tool call to point at. Pass it through, deduped against tool_calls that
repeat the same id
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

return AnthropicContentParamSourceText(
type="text",
media_type="text/plain",
data=base64.b64decode(image_chunk["data"]).decode(content_type_header.get_content_charset("utf-8")),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: Unbounded text document decoding

An authenticated caller can submit a very large text/plain data URI and force the worker to retain the original base64 string, decoded bytes, and decoded Unicode text simultaneously, exhausting worker memory. Reject documents whose encoded or decoded size exceeds a configured media limit before constructing the text source.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same shape as the existing base64 decodes at factory.py:3254 and token_counter.py:232; the max_request_size_mb middleware is the bound on all of them

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detail. I can't automatically confirm this is safe to dismiss, so I'm leaving the thread open for a maintainer to make the call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At ade0e42 an 8 MiB attachment peaks at 29.3 MiB as text and 21.3 MiB as PDF or PNG, so memory grows linearly (script)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detail. I can't automatically confirm this is safe to dismiss, so I'm leaving the thread open for a maintainer to make the call.

@veria-ai

veria-ai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

The PR routes PDF data URIs to Anthropic document blocks and shares the document transformation with Snowflake. It also updates text attachment decoding and tool-input conversion.

One issue has been addressed, but three remain open. Newly accepted tool-input formats let authenticated callers send protected text to Anthropic without the configured pre-call filtering. Text attachment handling also permits memory exhaustion through oversized data URIs and disproportionate CPU consumption through caller-selected decoding, leaving policy-enforcement and worker-availability concerns unresolved.

Open issues (3)

Fixed/addressed: 1 · PR risk: 6/10

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

A native `tool_use` block kept its raw id while the matching tool result
was sanitized, so replaying a conversation with an id like
`functions.Bash:0` still came back as a 400. Both sides go through the
same sanitizer now, dedupe compares the sanitized ids, and the block is
rebuilt from its own fields so stray keys and a string `input` do not
reach the provider.

An explicit `format` on an `image_url` or `file` block now decides both
whether the attachment is a document and what media type it carries, so a
PDF sent under a generic data URI mime reaches Claude as a document.

Snowflake turns an attachment whose data URI names an unknown charset
into a 400 naming that encoding instead of letting the lookup failure
surface as a 500.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

… count routes

The anthropic, azure_ai and Bedrock Mantle count handlers re-raise a BadRequestError raised before the provider call, and their token counters mark it rejected_before_provider_call, so a framing deployment answers the 400 instead of an estimate that leaves the attachment out, and Mantle no longer turns it into a 500
…flake_shared_anthropic_pt

# Conflicts:
#	litellm/litellm_core_utils/prompt_templates/factory.py
…s format

A downloaded text file reaches the decoder without its server's charset since main strips it, so the old hint to name the charset in the data URI could not help a URL caller. A file block's format takes text/plain;charset=... for both URLs and data URIs
@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

"""
import json

if isinstance(arguments, Mapping):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: New tool-input shapes bypass pre-call DLP

With a pre-call litellm_content_filter blocking/masking rule, an authenticated caller can now submit tool_calls[].function.arguments as {"value":"<protected text>"} and send that value to Anthropic unchanged: ContentFilterGuardrail._get_tool_call_arguments() skips non-strings, while this branch makes the provider conversion accept them instead of rejecting the request. The newly forwarded native tool_use.input blocks at factory.py:3459 also escape OpenAIChatCompletionsHandler._extract_inputs(), which only collects top-level tool_calls; normalize both representations before pre-call scanning, or extend extraction, argument scanning, and rewrite mappings to cover them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snowflake already forwarded both shapes unscanned at the base, so the gap is in the shared guardrail extraction, and it is tracked separately

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

…of an empty string

Snowflake sent json.dumps of a non-string tool result before it moved onto the shared transform, which then sent an empty string for a number or boolean, so Claude lost the answer. Mapping results were already serialized; numbers and booleans now take the same path, and None stays empty as it was on Anthropic
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

content_type_header["content-type"] = media_type_with_parameters
charset: Final = content_type_header.get_content_charset("utf-8")
try:
text: Final = base64.b64decode(data).decode(charset)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: Caller-selected charset enables quadratic decoding

An authenticated caller can send a file block with file_data set to data:text/plain;charset=punycode;base64, plus base64-encoded b'a' * 524288; Punycode repeatedly copies its growing output, and this approximately 699 KB payload took about 4 seconds in a source-isolated reproduction of the current attachment helper versus under 1 ms on the base revision. (raw.githubusercontent.com) On Bedrock-invoke and Snowflake, this conversion runs on the event loop, letting repeated requests stall unrelated traffic even with a 1 MiB request-size cap.

Restrict charset to an explicit allowlist of bounded-cost text encodings, such as UTF-8 and Latin-1, before calling .decode().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7d5bce3, which decodes only standard charsets, and fb753f0, which keeps the request out of the 400, so punycode answers in 0.12 s

# Conflicts:
#	litellm/litellm_core_utils/prompt_templates/factory.py
…n Claude routes

A BadRequestError raised by the shared message translation already names its problem, so it no longer carries every message as Received Messages. A 700 KB text attachment with an unsupported charset otherwise answered a 700 KB 400, and redacting that text held the event loop for about 40 s through the proxy.
…n Snowflake Claude

Snowflake Claude now builds its system prompt with the shared Anthropic transform, which keeps a message-level cache_control mark on a string system prompt the way the anthropic, vertex, and bedrock routes do. The base dropped that mark on Snowflake alone while it already sent the same block shape for marked system content lists.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…stead of sending the placeholder

The empty-text sanitizer only counted tool_calls, thinking, server_tool_use and tool result blocks as
content that survives the assistant converter, so a blank text part next to a replayed native tool_use
became the protocol placeholder and reached Claude as assistant text. A native tool_use now counts when
the next turn answers it, the same check the converter uses before keeping it, so the blank part is
dropped there and an unanswered tool_use still gets the placeholder, since the converter drops it and
the turn would otherwise be empty
…flake_shared_anthropic_pt

# Conflicts:
#	litellm/litellm_core_utils/prompt_templates/factory.py
…0, as main does

Main's #49237 answers 400 naming the first non-string role whatever error the conversion raised. This PR's handler
for deliberate translation 400s ran first and skipped that check, so an int or bool role answered "Invalid Message
passed in" at the merged tip. The handler now names the role first and keeps its own message otherwise.

Main's test for a dropped tool answer id used object tool call arguments as its later failure, which this PR
accepts on purpose, so that case now uses list arguments, which still fail.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…on knows

The allowlist kept Python codec names for one label per WHATWG encoding, so
labels that Python maps to a codec of its own (iso-8859-9, iso-8859-11,
tis-620, gb2312, big5-hkscs, ms932) answered 400 instead of decoding. All six
are linear table codecs, so the punycode and utf-7 rejection stands
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 21d08c8. Configure here.

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

risk:high Sensitive, broad, or high-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants