Repository navigation
fix(decisions): accept OpenAI input_json content parts on /v1/decisions - #52805
Merged
Merged
Conversation
User messages on the OpenAI-format /v1/decisions route can now carry input_json parts whose data is an object or an array of objects. OpenAI and Azure deployments forward them unchanged. Providers without JSON input answer 400 naming input_json, or drop the part under drop_params. An input_json part takes no prompt_cache_breakpoint, matching OpenAI.
Contributor
Contributor
Contributor
[Medium impact] The PR appears safe to merge, with no new actionable issues found.
|
Contributor
6 of 9 tasks
…d drop all input under drop_params
Contributor
…ut under drop_params
Contributor
Contributor
|
bugbot run |
… kept image types
Contributor
…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
Contributor
…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
Contributor
…ode and resume colliding key suffixes
Contributor
Contributor
|
bugbot run |
…equest carries a messages field
Contributor
Contributor
|
bugbot run |
Contributor
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 264f9f7. Configure here.
5 of 6 tasks
mateo-berri
added a commit
that referenced
this pull request
Nov 23, 2026
…rt_51220_lts_1_108_x Keeps main's DecisionsResponseValidationError beside the line's input_json, safety_identifier and missing-confidence handling, and ports #52805's Gemini hunk so Gemini skips input_json parts the line now has
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Handwritten 1-3 sentence description
/v1/decisions 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_jsonpart takes noprompt_cache_breakpoint, because OpenAI answers 400 unknown_parameter for it. Withoutdrop_paramsthe gateway answers 400, and with it the breakpoint is dropped, per litellm's convention for an unsupported paraminput_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, which matches how fix(decisions): forward OpenAI prompt cache fields #51457 treated the developer role. Forwarding it unverified is the alternative, and stays open for anyone who can test Vercelinput_jsonthereinput_json(string or scalar data, or the part in a developer message) is refused even underdrop_params, like an image in a developer message today. Dropping it like a malformed image URL is the alternativeinput_jsonskips the deployments that would refuse it, unless that leaves none. This is how the router already treats audio and videos. 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, the same as audio and videos, 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 and developer and system messages 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 user message holds onlyinput_jsongoes only to the deployments that take JSONspend_logs_prompt_storage: latest_turn) show aninput_jsonpart as[json omitted], like[image omitted]for an image. Storing the JSON there is the alternative, which would copy caller records into spend logsdataas 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 textScreenshots / Proof of Fix
Before is the merge base 436f6d5 and After is e74b5be, 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 Gemini (gemini-decision-1) with curl. The OpenAI SDK run is under Round 1Last updated: 264f9f7, 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_KEYandGEMINI_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 e74b5be and at fd71cae, and from OpenAI directly
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 436f6d5)
After (head e74b5be)
The same body sent straight to OpenAI gives the same answer
openai-direct.json, which is customer.json with OpenAI's model name
{"model": "gpt-6-luna", "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?"}]}At fd71cae
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 436f6d5)
After (head e74b5be)
Gemini deployment without drop_params
Request body
gemini.json{"model":"litellm-qa-decisions-gemini","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 436f6d5)
After (head e74b5be)
Gemini deployment with drop_params
Request body
gemini-drop.json{"model":"litellm-qa-decisions-gemini-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 436f6d5)
After (head e74b5be)
prompt_cache_breakpoint on an input_json part
Request body
breakpoint.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]}}, "prompt_cache_breakpoint": {"mode": "explicit"}}]}], "questions": [{"type": "predicate", "name": "duplicate_charge", "instructions": "Does the ticket describe a duplicate charge supported by the order?"}]}Before (base 436f6d5)
After (head e74b5be)
The same body sent straight to OpenAI, as
breakpoint-openai-direct.jsonwith OpenAI's model name, gets OpenAI's own 400Round 1 cases, OpenAI SDK and spend logs
Before is the merge base 436f6d5 and After is bea2584, on 2 workers each with Redis
client.decisions.create[json omitted]The rest is in
main-round1.mdin the gistRound 4 cases, secret redaction and gif images
Before is the previous tip c4bdb8e and After is fd71cae, on the same rig. The base rejects
input_jsonwith a 400input_json[REDACTED]reached OpenAIinput_json, 8 callsConfig, commands and output
The Round 1 config gets these entries.
python3 recorder.py 29573 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 436f6d5
Before, previous tip c4bdb8e
After, fd71cae
Round 5 cases, colliding secret keys and LLM Shield keys and numbers
Before is the previous tip dd0bfd2 and After is d85536a, 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-main-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 amain-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 (dd0bfd2)
After (d85536a)
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 d85536a, or b9e4e57 for the last row, and After is 264f9f7. 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, andmain-out_cisco_before.txtandmain-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 d85536a
After, at b9e4e57
/live-pr-risk
Cells at b9e4e57
The head leg ran every earlier cell again at b9e4e57 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 d85536a run. All 29 cells are SAMEThe recorder got this
dataat b9e4e57. Secret keys keep their numbered names. LLM Shield picks new fake values on every call, so only their shape matches the d85536a run, with every email and phone number maskedThe base 436f6d5 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 b9e4e57 to 264f9f7
264f9f7 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 b9e4e57 run. The Cisco cells ran again at 264f9f7, inmain-out_cisco9_after.txtin the gist, and the Cisco unit tests passCells at the merge base 436f6d5 and at c4bdb8e
Both legs ran on the rig from Round 1 cases above, with the same config, 2 workers, and their own Postgres and Redis, against real OpenAI, Gemini and TypeSafe. The last column is the provider each call reached, read from
x-litellm-model-api-base. The cdbe001 run also logged every upstream request body through a forwarding recorder and found them identical base against head on the cells that answer 200 on both sidesdata, OpenAI[json omitted]The last three rows are the drop_params choice in the Decisions block. With text in the user message, Gemini stays a candidate, drops the JSON part, and decides on the text. With only JSON in the user message, Gemini is skipped even next to a developer message, since Gemini drops that message too and would have nothing left to decide on
Raw status, model and api-base of every mixed-group call
cases.shabove also runsmixed-json-only-dropand thenmixed-dev-json-only-drop8 times each at the end. Each leg's output went toout_<leg>_r3.txt, andcalls.pyprints each mixed call's status, the answering model andx-litellm-model-api-base. Two worker PIDs andREDIS_HOSTwere checked under each head proxy at c4bdb8ecalls.py
mixed.json
{"model": "litellm-qa-decisions-mixed", "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?"}]}mixed-text-only.json
{"model": "litellm-qa-decisions-mixed", "input": [{"role": "user", "content": [{"type": "input_text", "text": "Evaluate the ticket using the order evidence."}, {"type": "input_text", "text": "Ticket: 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?"}]}mixed-drop.json
{"model": "litellm-qa-decisions-mixed-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?"}]}mixed-json-only-drop.json
{"model": "litellm-qa-decisions-mixed-drop", "input": [{"role": "user", "content": [{"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?"}]}mixed-dev-json-only-drop.json
{"model": "litellm-qa-decisions-mixed-drop", "input": [{"role": "developer", "content": "Judge the ticket against the order evidence."}, {"role": "user", "content": [{"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?"}]}Array, Gemini and breakpoint cells
cases4.shruns the four cases with the samerunascases.sh, on the same two legs.array.json,gemini-drop.jsonandbreakpoint.jsonare the bodies under Screenshots / Proof of Fix.gemini.jsonsends the headline Gemini body tolitellm-qa-decisions-gemini-fallbackwith"disable_fallbacks": true, since that is this config's Gemini group without drop_paramsBase 436f6d5
Head c4bdb8e
gemini.json
{"model": "litellm-qa-decisions-gemini-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_tokensinput_jsonis cooling down, the call gets a 400 from one that refuses it, as audio and video calls do todayFinal Attestation
Bugbot summary