Repository navigation
fix(decisions): accept OpenAI input_json content parts on /v1/decisions - #52807
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
[Medium impact] The latest change appears safe to merge and closes the Cisco combined-field bypass
|
…ut under drop_params
|
bugbot run |
surlymochan
left a comment
There was a problem hiding this comment.
Read through the full diff. The routing itself looks sound: OpenAIDecisionsConfig.supports_json_input = True while the Vercel gateway explicitly opts out (False), and unsupported providers get the input_json parts stripped via without_json_input instead of failing the call; has_json_input/without_json_input correctly no-op on DecisionsIRState, which cannot carry message parts. I also checked request_carries_json_input against the helpers in mid_conversation_system.py — parts_of returns () for a plain-string input and message_field returns None for non-mapping messages, so a string input cannot crash that path.
One thing worth clearing up before review: this overlaps heavily with your own #52805 (same title, same author, branch litellm_decisions_input_json, also OPEN). #52805 is broader — it also touches litellm/llms/gemini/decisions/transformation.py, spend-tracking utils, and router_rust — while this PR (..._lts) is narrower. Which one is canonical? Two open PRs with the same title will split review and risk conflicting merges; if #52805 is superseded, closing it (or noting so here) would help maintainers pick the right one.
Non-blocking otherwise — the input_json handling and test coverage in tests/unit/decisions/test_main.py + the OpenAI-format wire test look thorough.
… kept image types
…co, count only surely kept images hide_secrets now checks each input_json value with its key in front and rewrites secrets found in keys too. LLM Shield scans the strings in input_json data, and Cisco AI Defense scans the data as JSON text and falls back to on_flagged_action in redact mode, since it cannot write redacted text back into JSON The drop_params check that skips a deployment the drop would leave with no input now counts an image as kept only when it is well formed and its media type is known to be one the deployment takes
…eld mask keys and numbers hide-secrets now gives a key that redacts to an existing name a numbered suffix, so two secret keys in one object no longer collapse into one value. LLM Shield now sends input_json keys and numbers to the shield too, writes a number back only when the shield changed it, and renames keys after every value write so no value lands under an old key
…ode and resume colliding key suffixes
|
bugbot run |
…equest carries a messages field
|
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 2c031e1. Configure here.
Handwritten 1-3 sentence description
/v1/decisions on the LTS line now accepts OpenAI's input_json content parts, so structured evidence like an order record can go straight to OpenAI instead of being stuffed into text first. Providers that can't take JSON input refuse it with a clear 400, or drop it when the deployment sets drop_params
Details
TLDR
Problem this solves:
How it solves it:
User Flow
Before: the gateway answers 400 to a decisions request that OpenAI accepts
input_textpart and aninput_jsonpartInput tag 'input_json' found using 'type' does not match any of the expected tagsAfter: the same request gets OpenAI's decision
input_json, or drops the part underdrop_paramsRelevant issues
Part of #49127, which asks for every OpenAI Decisions request feature. This PR covers only
input_jsonLinear ticket
Resolves LIT-10883
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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 moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Decisions and the alternatives not taken
datamust be an object or an array of objects, because OpenAI answers 400 invalid_type for a string or an array of scalars. The alternative was any JSON value with OpenAI refusing it, which costs a round trip and gives a different error per providerinput_json, or drops the part underdrop_params. Rendering the JSON as text for those providers was not chosen, since it changes what the model sees without the caller askinginput_jsonamong the part types it takes. Its 400 for aninput_xmlpart says "Supported values are: 'input_text', 'input_image', and 'input_json'". No Azure Decisions model answers a call yet, so there is no live Azure leg, and a unit test checks that Azure gets the part unchanged. Vercel AI Gateway does not inherit it, since nothing shows its decisions schema takesinput_json. Forwarding it unverified is the alternative, and stays open for anyone who can test Vercelinput_json(string or scalar data) is refused even underdrop_params, the same as on main (fix(decisions): accept OpenAI input_json content parts on /v1/decisions #52805).drop_paramsdrops a part a provider does not support, and no provider takes malformeddata, since OpenAI's reference requires an object or an array of objects. Dropping it, as this line does for a malformed image part, is the alternativeinput_jsonskips the deployments that would refuse it, unless that leaves none. Letting each pick refuse on its own was the alternative, and it made the same request answer 400 or 200 depending on which deployment was picked. Underdrop_paramsa deployment without JSON input stays a candidate when the request has other input, and drops the part, so one request can be decided with or without the evidence. Preferring the deployments that take JSON even then is the alternative not taken, sincedrop_paramsis how a caller says a dropped part is acceptable. A deployment is still skipped when the drop would leave it no input, counting the images it also drops, since it would answer 400. An image counts as kept only when its data URL or base64 type is one the deployment takes, so an image URL counts as dropped on a deployment that takes only some image types, since the router cannot see a URL's type without fetching it. Fetching each image in the router was the alternative, which adds a download to every routing decision. So a request whose input is onlyinput_jsonparts, or those parts and images, goes only to the deployments that take JSONdataas one JSON string.hide_secretsredacts the secrets it finds in the string values and keys insidedatain place, and leaves numbers and the structure as they are. When two keys in one object redact to the same text, the next one gets a number, as in[REDACTED] (2), so no value is overwritten. Sending the redacted JSON as text was the alternative, which would change the part type OpenAI getsdata, since a phone or account number can be the personal detail itself. A number it masks comes back as the masked string, so that value changes from a number to a string, and the numbers it leaves alone keep their type. The same walk runs oninput_jsonparts sent to/v1/responses. Skipping numbers was the alternative, which sent them to the provider unmaskedinput_jsondata in place, so aredactverdict on a request whoseinputcarries it answers 400 in every mode, monitor included, whatever other fields the request has. Letting it through unredacted in monitor mode, as happens to other input Cisco cannot rewrite, was the alternative, but that sends the flagged data to the provider. Rewriting the input as Cisco's sanitized text was not chosen either, since it turns the JSON into textHow this differs from the main PR
The main change does not cherry-pick onto lts/1.108.x, so this is a port of the same behavior to the line's older decisions code. Content parts on this line have no
prompt_cache_breakpoint, so there is no breakpoint handling or test. Messages here are user-only, so there is no developer-message test. The line has no Gemini decisions provider, so TypeSafe is the provider whose text building skips JSON parts, and the drop_params test covers both Perplexity and TypeSafe. The line has no_supported_messages, so dropping images and dropping input_json both happen in_without_unsupported_params. The tests use this line'sopenai_default_basefixture. Main skips deployments that would refuseinput_jsonin a mixed model group by extending its Decisions audio and video filter. This line has no such filter, so the port adds one to the router's healthy-deployment step, next to the check that a deployment can serve the route. Main's[json omitted]placeholder for spend logs is not ported, since this line has no latest-turn prompt storage, and the pair block records it as main-only. Main redactsdatawith its existing walk over tool-call JSON. This line has no such walk, so the port adds one that loops instead of recursing, so deepdatacannot hit Python's recursion limite74b5be831227e7ff30b67cb42297670f8cd7de8792715531287cdc8664ebf6aad09a82e2dfc445a886057a552f811656527cd8c68e51a7bc8d9937dcdbe001e9c8f9e55e5db3cc669d90e3a0be4a7a3971a4e3bceec6f2337003a3c9feb67d2ea1f7ef2d43574dc1f9971a4e3bceec6f2337003a3c9feb67d2ea1f7ef2bea258420fa2b1116d89c859166e8db064ffef50971a4e3bceec6f2337003a3c9feb67d2ea1f7ef2, spend-log part main-only1d446a7f0bd84f25b70ef923a0b6da67daaf2cc634f617c5219d8d72fad50c738c3faa6daf9a0153c4bdb8e34b260d8a85d099668f611156229bb10e34f617c5219d8d72fad50c738c3faa6daf9a0153fd71cae85149877b02040f30c0d7cf663b227d07f2fa8904ed254ca9f097aaafda2d0043e8cbdd21dd0bfd2236a99645180b8b63a7b9cacf17becbe8ecd11a162073557fed079849d82722a82e035913d85536a675e25f6de30b06cf7e2bef8b0e77c8963e5f3d895d61a5d8e96bbf23aaf70fd80443595cb9e4e57fa633912a31af16d5ffab0987ce0059becaa9ae203f7e08e2d7e65dbb96a643bcdca86b81264f9f703aa2c031e1d859Screenshots / Proof of Fix
Before is the LTS merge base f76134d and After is 7927155, each on 2 uvicorn workers with its own Postgres on the shared QA box and no Redis. Calls went to real OpenAI (
gpt-6-luna) and real TypeSafe (jev-1.14.0). The OpenAI SDK run is under Round 1Last updated: 2c031e1, where the unit tests and
make checkpass. /live-pr-risk below repeats every rounddata, OpenAIdata, OpenAIHeadline case, object
datasent to OpenAILITELLM_MASTER_KEY,OPENAI_API_KEYandTYPESAFE_API_KEYset, and--num_workers 2cases.shwithPROXY_URLset to the proxy andLITELLM_MASTER_KEYexported. It prints each command before it runs itRequest body and output at the base, at 7927155 and at f2fa890
Request body
customer.json{"model": "litellm-qa-decisions", "input": [{"role": "user", "content": [{"type": "input_text", "text": "Evaluate the ticket using the order evidence."}, {"type": "input_json", "data": {"ticket": {"body": "Please refund the duplicate charge."}, "order": {"charges": [49, 49]}}}]}], "questions": [{"type": "predicate", "name": "duplicate_charge", "instructions": "Does the ticket describe a duplicate charge supported by the order?"}]}Before (base f76134d)
After (QA tip 7927155)
At f2fa890
config.yaml and cases.sh
Array of objects as `data`
Request body
array.json{"model": "litellm-qa-decisions", "input": [{"role": "user", "content": [{"type": "input_text", "text": "Evaluate the ticket using the order evidence."}, {"type": "input_json", "data": [{"body": "Please refund the duplicate charge."}, {"charges": [49, 49]}]}]}], "questions": [{"type": "predicate", "name": "duplicate_charge", "instructions": "Does the ticket describe a duplicate charge supported by the order?"}]}Before (base f76134d)
After (QA tip 7927155)
TypeSafe deployment without drop_params
Request body
typesafe.json{"model": "litellm-qa-decisions-typesafe", "input": [{"role": "user", "content": [{"type": "input_text", "text": "Evaluate the ticket using the order evidence."}, {"type": "input_json", "data": {"ticket": {"body": "Please refund the duplicate charge."}, "order": {"charges": [49, 49]}}}]}], "questions": [{"type": "predicate", "name": "duplicate_charge", "instructions": "Does the ticket describe a duplicate charge supported by the order?"}]}Before (base f76134d)
After (QA tip 7927155)
TypeSafe deployment with drop_params
Request body
typesafe-drop.json{"model": "litellm-qa-decisions-typesafe-drop", "input": [{"role": "user", "content": [{"type": "input_text", "text": "Evaluate the ticket using the order evidence."}, {"type": "input_json", "data": {"ticket": {"body": "Please refund the duplicate charge."}, "order": {"charges": [49, 49]}}}]}], "questions": [{"type": "predicate", "name": "duplicate_charge", "instructions": "Does the ticket describe a duplicate charge supported by the order?"}]}Before (base f76134d)
After (QA tip 7927155)
Round 1 cases, OpenAI SDK and mixed groups
Before is the line's base f76134d and After is 971a4e3, on 2 workers each with Redis
The rest is in
lts-round1.mdin the gistRound 4 cases, secret redaction and gif images
Before is the previous tip 34f617c and After is f2fa890, on the same rig
input_json[REDACTED]reached OpenAIinput_json, 8 callsConfig, commands and output
The Round 1 config gets these entries.
python3 recorder.py 29574 upstream.logruns on the QA box, logs each body it gets, and forwards it to OpenAI. Each leg ranLEG=<leg> PROXY_URL=<leg proxy> zsh cases5.sh > out_<leg>_r4.txt, and the recorder log was copied after each legsecret-json.json{"model": "litellm-qa-decisions-recorded", "guardrails": ["hide-secrets"], "input": [{"role": "user", "content": [{"type": "input_text", "text": "Review this deploy config."}, {"type": "input_json", "data": {"deploy": {"env": "AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLF"}, "replicas": 2}}]}], "questions": [{"type": "predicate", "name": "key_masked", "instructions": "Is the value of deploy.env exactly the text AWS_ACCESS_KEY_ID=[REDACTED], with no access key id in it?"}]}gif-json.json{"model": "litellm-qa-decisions-gif", "input": [{"role": "user", "content": [{"type": "input_image", "image_url": "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"}, {"type": "input_json", "data": {"order": {"charges": [49, 49]}}}]}], "questions": [{"type": "predicate", "name": "duplicate_charge", "instructions": "Does the order show a duplicate charge?"}]}cases5.shspend_guard.pycalls5.pyrecorder.pyBase f76134d
Before, previous tip 34f617c
After, f2fa890
Round 5 cases, colliding secret keys and LLM Shield keys and numbers
Before is the previous tip ecd11a1 and After is 3e5f3d8, on the same rig. The recorder shows what reached OpenAI
Config, commands and output
LLM Shield ran on the QA box from the
ghcr.io/ninadphalak/llm-shield-proxyimage on port 26796, and the Round 4 config gets this guardrail. The rig wrote the shield's key inline, and here it is read fromLLM_SHIELD_API_KEYEach leg ran
LEG=<leg> RIG=dec-json-lts-r1 PROXY_URL=<leg proxy> zsh cases6.sh. It empties the recorder log before each file and then prints theinput_jsonthe recorder got.cases6.sh,input_json_seen.pyand the full output of every leg are in the gist with alts-prefixsecret-collide.json{"model": "litellm-qa-decisions-recorded", "guardrails": ["hide-secrets"], "input": [{"role": "user", "content": [{"type": "input_text", "text": "Review this usage report."}, {"type": "input_json", "data": {"usage": {"AKIAIOSFODNN7EXAMPLF": {"calls": 3}, "AKIAIOSFODNN7EXAMPLD": {"calls": 5}}}}]}], "questions": [{"type": "predicate", "name": "both_kept", "instructions": "Does usage hold two entries, one with calls 3 and one with calls 5?"}]}shield-json.json{"model": "litellm-qa-decisions-recorded", "guardrails": ["llm-shield"], "input": [{"role": "user", "content": [{"type": "input_text", "text": "Review this customer record."}, {"type": "input_json", "data": {"jane.doe@example.com": {"phone": 4155550100, "visits": 3, "score": 0.5, "vip": true}, "ids": [4155550100, 7], "note": "call jane.doe@example.com"}}]}], "questions": [{"type": "predicate", "name": "has_vip", "instructions": "Is any customer in the record marked vip?"}]}Before (ecd11a1)
After (3e5f3d8)
The base answers
HTTP 400withInvalid Decisions requestto both files, and the recorder gets nothingRound 6 cases, Cisco AI Defense redact on input_json
Before is the previous tip 3e5f3d8, or caa9ae2 for the last row, and After is 2c031e1. A local stub answers for Cisco AI Defense, since there is no Cisco QA account, and OpenAI is real
messagesConfig, commands and output
The Round 5 config gets the two guardrails below.
cisco_stub.pyin the gist answersPOST /api/v1/inspect/chatwith"action": "redact"and asanitized_text, or asanitized_messageswhen the inspected text holdsMSGS.cases_cisco.shthere sends the four bodies, andlts-out_cisco_before.txtandlts-out_cisco_after.txthold the full outputFirst case's body
{"model": "litellm-qa-decisions-recorded", "guardrails": ["cisco-redact"], "input": [{"role": "user", "content": [{"type": "input_text", "text": "Check customer"}, {"type": "input_json", "data": {"customer": {"ssn": "123-45-6789"}}}]}], "questions": [{"type": "predicate", "name": "has_ssn", "instructions": "Does the evidence include a full social security number?"}]}Before, at 3e5f3d8
After, at caa9ae2
/live-pr-risk
Cells at caa9ae2
The head leg ran every earlier cell again at caa9ae2 with Redis, through
tip_run.shandcases7.shin the gist.cmp_cells.pyprints SAME when a cell keeps its status, answer, api-base host and fallback count against the 3e5f3d8 run. All 26 cells are SAMEThe recorder got this
dataat caa9ae2. Secret keys keep their numbered names. LLM Shield picks new fake values on every call, so only their shape matches the 3e5f3d8 run, with every email and phone number maskedThe base f76134d rejects the first two with a 400 before any call, and OpenAI answers both sides'
/v1/responsescall with the same 400,Invalid value: 'input_json'Carry from caa9ae2 to 2c031e1
2c031e1 changes one condition in the Cisco AI Defense guardrail, so a
redactverdict on a request whoseinputcarriesinput_jsonis refused even when the request also has amessagesfield. Only a Ciscoredactverdict reaches that line, so the other cells keep the caa9ae2 run. The Cisco cells ran again at 2c031e1, inlts-out_cisco9_after.txtin the gist, and the Cisco unit tests passCells at base f76134d and at 34f617c
Both legs ran on the rig from Round 1 cases above. The last column is the provider each call reached, read from
x-litellm-model-api-base. TypeSafe answers carry no such header, so in a mixed group a call without it is a TypeSafe call. The 886057a run also logged every upstream request through a forwarding recorder and found the bodies identical base against head on the cells that answered 200 on bothdata, OpenAIThe last three rows are the drop_params choice in the Decisions block. With text in the request, TypeSafe stays a candidate, drops the JSON part, and decides on the text. With only JSON, or JSON and an image, TypeSafe is skipped, since it drops both and would have nothing left to decide on
Raw status, model and api-base of every mixed-group call
This block moved to
lts-raw-mixed-group-calls-34f617c5219.mdin the gist to keep the body under GitHub's size limit. It holds thecalls.pyoutput for every mixed-group call at the base and at 34f617c, the two worker PID andREDIS_HOSTchecks, and the request bodiesArray and TypeSafe cells
cases4.shruns the three cases with the samerunascases.sh, on the same two legs.array.jsonandtypesafe-drop.jsonare the bodies under Screenshots / Proof of Fix.typesafe.jsonsends the headline TypeSafe body tolitellm-qa-decisions-typesafe-fallbackwith"disable_fallbacks": true, since that is this config's TypeSafe group without drop_paramsBase f76134d
Head 34f617c
typesafe.json
{"model": "litellm-qa-decisions-typesafe-fallback", "input": [{"role": "user", "content": [{"type": "input_text", "text": "Evaluate the ticket using the order evidence."}, {"type": "input_json", "data": {"ticket": {"body": "Please refund the duplicate charge."}, "order": {"charges": [49, 49]}}}]}], "questions": [{"type": "predicate", "name": "duplicate_charge", "instructions": "Does the ticket describe a duplicate charge supported by the order?"}], "disable_fallbacks": true}cases4.sh
Type
🐛 Bug Fix
Caveats (if any)
Medium
Low
messagesfield still skips Cisco's redaction, as before this PR. It is filed as a follow-updatagets a rawPydanticSerializationError. The proxy is not affectedinput_jsondata, which matters only for a hand-set smallmax_input_tokensosv-scanis red on lts/1.108.x itself too. This PR changes no dependenciesFinal Attestation
Bugbot summary