Repository navigation
fix(aiguard): evaluate LiteLLM proxy /v1/responses and /v1/messages answers - #22038
Conversation
…nswers In the LiteLLM proxy, the AI Guard guardrail evaluated the prompt of /v1/responses and /v1/messages requests but never their answers. It did not claim these requests, and litellm sends them with its own HTTP client, so no provider listener evaluated the answers either. The /v1/messages prompt check also dropped the system prompt and the tool_use and tool_result blocks. In post_call mode the guardrail now claims these requests and evaluates their non-streamed answers once, with the prompt rebuilt from the request body. Responses answers carry the hosted MCP servers of the request tools. /v1/messages prompts go through the Anthropic converter; when it cannot read a body, the guardrail evaluates the chat conversion of the messages and does not claim the request. Jira: APPSEC-71907 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
BenchmarksBenchmark execution time: 2026-11-25 13:41:05 Comparing candidate commit 43973c4 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 404 metrics, 9 unstable metrics.
|
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
Mixed Messages turns can bypass user-text rules because conversion puts a tool result last and then suppresses the provider check. Saved Responses prompts also lose MCP server identity when their tools are resolved server-side.
🤖 Bits Code Review · Commit 20c5f61
…onses tools The Anthropic converter emitted the text of a user turn before its tool_result messages, so new user text was not the last turn. Tool results answer the previous assistant turn, so they now come first. For /v1/responses answers in the LiteLLM proxy, the hosted MCP servers fall back to the tools echoed in the response when the request has none (saved prompts), as the OpenAI integration does. Jira: APPSEC-71907 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
More details
The PR adds AI Guard evaluation of non-streamed LiteLLM Responses and Messages answers.
Mixed Messages ordering now preserves user-text checks.
Saved prompts now retain MCP server identity.
Both earlier findings are resolved; no issues remain open.
Streamed answers remain unevaluated; full suites were not rerun for this update.
🤖 Bits Code Review · Commit cbc2bef
…wers The pre-call check of LiteLLM proxy Responses requests now uses the Responses input converter, because litellm drops the variables of a saved prompt that the provider still gets. The guardrail now claims a proxy request only when its post-call hooks evaluate the answer: chat and text completions, and Responses and Messages requests that are not streamed and use a create route. Streamed Responses and Messages requests and /cursor/chat/completions keep the provider listener checks. Jira: APPSEC-71907 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
The PR adds AI Guard evaluation of non-streamed LiteLLM Responses and Messages answers.
Earlier Messages ordering and saved-prompt MCP identity defects remain fixed.
The latest commit preserves provider checks for unevaluated routes and streams.
One issue remains: LiteLLM-supported Responses text blocks can bypass prompt evaluation.
Full suites were not rerun.
🤖 Bits Code Review · Commit 84854e7
The LiteLLM proxy accepts chat-style text parts in a Responses input and sends them to the model, but the Responses converter reads only input_text and output_text parts. The guardrail now reads them as input_text parts, in a copy, for the prompt and answer checks. Jira: APPSEC-71907 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
The PR evaluates non-streamed LiteLLM Responses and Messages answers.
Messages ordering and saved-prompt MCP identity defects remain fixed.
This commit restores chat-style text inside user messages.
The same content-loss defect remains in function-call outputs, leaving tool-result injections unchecked.
Streamed answers remain unevaluated; full suites were not rerun.
🤖 Bits Code Review · Commit f1c25ce
Co-authored-by: datadog-datadog-prod-us1-2[bot] <261164178+datadog-datadog-prod-us1-2[bot]@users.noreply.github.com>
There was a problem hiding this comment.
More details
AI Guard evaluates non-streamed LiteLLM Responses and Messages answers.
Messages ordering and saved-prompt MCP identity defects are fixed.
Chat-style text is preserved in user messages and function-call outputs.
All reported findings are resolved; none remain open.
Streamed answers remain unevaluated; full suites were not rerun.
🤖 Bits Code Review · Commit 766d123
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 43973c4 | Docs | View more details | Give us feedback! |
Reformat the tool output branch of _responses_text_parts, which was over the line length, and test that chat-style text parts of a function_call_output are evaluated. Jira: APPSEC-71907 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
Build pipeline has failing jobs for 58bb310: What to do next?
This build will be kept for 3h more. During that period, you can retry the pipeline or the failing jobs and then re-run the same command! |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
…thropic-evaluate-mcp-connector Resolve the conflicts with #22038: keep the in-order content walk and apply its rule there, so the tool results of a user turn come before that turn's text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Description
Jira: APPSEC-71907
A LiteLLM proxy can run the Datadog AI Guard guardrail in
pre_callandpost_callmode. #21845 made the guardrail own the AI Guard evaluation of chat and text completion requests in the proxy, and left/v1/responsesand/v1/messagesrequests to the provider listeners. But litellm sends these requests with its own HTTP client (its Responses API and Anthropic Messages handlers). For/v1/messagesto an OpenAI model it can also go throughchat.completions.with_raw_response, whose answer the OpenAI integration cannot read. As a result:mcp_callandmcp_approval_requestitems, were never evaluated, and thepost_callmode could not block them./v1/messages, the guardrail's prompt conversion dropped the system prompt and thetool_useandtool_resultblocks, so a prompt injection inside a tool result never reached AI Guard. The OpenAI integration also evaluated the prompt a second time.Changes in
ddtrace/aiguard/integrations/litellm.pypost_callmode, the guardrail claims a request only when its post-call hooks evaluate the answer: chat and text completions as before, and now non-streamedresponses,aresponsesandanthropic_messagesrequests on a create route (/responsesor/v1/messages). The provider listeners skip a claimed request. Streamed Responses and Messages requests and/cursor/chat/completionsare not claimed, so the provider listeners keep their checks there.instructions,inputand thepromptvariables of a saved prompt are evaluated. litellm's own conversion drops the variables. If the converter fails, litellm's conversion still runs./v1/responses: the Responses converter, with the hosted MCP servers of the requesttools(mcp_serversandmcp.server_id, gated byDD_AI_GUARD_MCP_ENABLED, as in the OpenAI integration);/v1/messages: the Anthropic converter.input_itemsandcompactanswers are not.instructions,inputandprompt; Anthropicsystemandmessages), never from the request metadata, which the client controls./v1/messagesprompts. The Anthropic converter now converts them, so the system prompt,tool_useandtool_resultare evaluated. Before the conversion, the guardrail reads each string item of the content lists as a text block, in a copy, because litellm forwards these items to the model as text.toolsdeclaration that cannot be read only drops the MCP metadata..cursor/rules/ai-guard.mdcdescribes the new claim conditions, the route rule, the fallback and the known limit below.pre_callandpost_callmodes)/v1/responses, not streamed/v1/messages, not streamed/v1/messagesthat the Anthropic converter cannot read/v1/responsesand/v1/messages, streamed/v1/messagesto OpenAI models on the chat path)Customer impact
With the guardrail in
post_callmode, a LiteLLM proxy now evaluates the non-streamed answers of/v1/responsesand/v1/messagesrequests and can block them./v1/messagesprompts are evaluated with their system prompt, tool calls and tool results. The release note describes the fix.Testing
scripts/run-tests:ai_guard_litellm_guardrailpasses on all 10 environments (litellm 1.78.5 and 1.82.6, Python 3.10 to 3.14), 249 tests in each.test_litellm_guardrail.py:mcp_serversandmcp.server_id, and without them whenDD_AI_GUARD_MCP_ENABLED=false;post_callmode;test_litellm_proxy.pysend requests through the LiteLLM proxy app in process, with offline stubs:/v1/responses, and/v1/messageson the chat path, on the litellm 1.82.6 Responses adapter and on the native Anthropic path, get one prompt and one answer evaluation from the guardrail and none from the provider listeners;tool_resultis blocked;/v1/messagesassertion that codified the gap ([("litellm", "prompt"), ("openai", "prompt")]) now expects one guardrail prompt and one guardrail answer.litellm.pyofmain, 64 of the 249 tests fail.scripts/lint checks, the type comment check andreno lintpass.Risks
post_callmode, a non-streamed/v1/responsesor/v1/messagesrequest now waits for one more AI Guard evaluation (the answer), as chat completions already do./v1/messagesbody that the Anthropic converter cannot read gets two prompt evaluations when litellm sends it through the OpenAI SDK: one from the guardrail and one from the OpenAI integration..cursor/rules/ai-guard.mdc: litellm's chat completions adapter for/v1/messagescan send animageblock inside atool_resultto the model as tool text (for example litellm 1.78.5 for OpenAI and Azure OpenAI models). The guardrail evaluates that block as an image, not as text./v1/responsesand/v1/messagesanswers are still not evaluated.Additional Notes
ai_guard_litellm_guardrailsuite ran.scripts/run-tests --listalso selects other suites through theddtrace/aiguard/*pattern; CI runs them.🤖 Generated with Claude Code