litellm/tests/unit/proxy/guardrails
ryan-crabbe-berri 4e1cd40ac5
fix(responses): answer Codex compaction_trigger on the chat-completions bridge (#53266)
* fix(responses): answer Codex compaction_trigger on the chat-completions bridge

Codex's remote compaction v2 ends the Responses input with a compaction_trigger
item and expects exactly one compaction output item back. The Responses to chat
completions bridge dropped the trigger as a content-less item, so Claude on
Bedrock (and every other bridged provider) answered a normal turn and Codex
failed with "expected exactly one compaction output item, got 0".

When the input ends in a compaction_trigger, the bridge handler now swaps it
for the gateway's existing compact summary prompt in the same upstream call and
returns the reply as one summary-only compaction item, streamed or not. That
item is the shape the bridge already replays as a summary on later turns. Text
and tool calls from the summary turn stay out of the output, and a reply with no
summary is a 502 so the client retries. Requests without a trailing trigger are
unchanged.

The strict claude_bedrock xfail on the Codex auto-compaction e2e row is removed.

* fix(responses): let a compaction summary turn write text when the caller forces a tool

A forced tool_choice on a request ending in compaction_trigger made the model
call a tool instead of writing the summary, so every retry came back as a 502.
The summary turn now relaxes a forced choice to auto and keeps the tools.

* fix(responses): bill, scan and parse compaction summaries safely

Three gaps around the summary a compaction_trigger turn returns.

A client that disconnected mid-summary was billed no output tokens, because
the bridge saved each streamed chunk after hiding its summary text. It now
saves the chunk as received and hides the text only from what the client sees.

Purview's output scan read message text and tool arguments but not the summary
inside a compaction item, so a summary went out unscanned. It now reads it
through the same reader the shared Responses guardrails use.

The summary-tag parse used a pattern that took seconds on a reply full of
unclosed tags. It now finds the tags with two linear searches, which also
covers the /v1/messages compaction editor that shares it.

* refactor(responses): drop a comment that restates the compaction 502

* test(responses): expect the mid-stream error a dropped summary stream raises
2026-11-21 14:53:31 -08:00
..
guardrail_hooks fix(responses): answer Codex compaction_trigger on the chat-completions bridge (#53266) 2026-11-21 14:53:31 -08:00
__init__.py
test_anthropic_sse.py fix(guardrails)!: keep the upstream error when a /v1/messages stream ends in one (#49088) 2026-10-31 02:56:20 -07:00
test_auto_router_compression.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_content_filter_path_traversal.py
test_content_utils.py fix(decisions): accept OpenAI input_json content parts on /v1/decisions (#52805) 2026-11-20 13:33:36 -08:00
test_custom_code_security.py fix(guardrails): mask reasoning text on /v1/responses output (#52504) 2026-11-19 01:25:06 -08:00
test_deferred_guardrail_logging.py fix(logging): retain streaming success logging tasks until they finish (#52067) 2026-11-16 11:21:05 -08:00
test_endpoint_image_scan.py feat(guardrails): scan an image on /apply_guardrail with a Bedrock guardrail (#51016) 2026-11-17 18:13:28 +00:00
test_guardrail_coverage.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
test_guardrail_endpoints.py feat(guardrails): scan an image on /apply_guardrail with a Bedrock guardrail (#51016) 2026-11-17 18:13:28 +00:00
test_guardrail_helpers.py feat(guardrails): reject requests that name an unregistered guardrail when reject_unregistered_guardrails is on (#53214) 2026-11-20 18:39:29 -08:00
test_guardrail_initializers.py refactor(types): replace Any with proven types in 157 files (#44798) 2026-10-06 15:31:54 +00:00
test_guardrail_load_balancing.py test: migrate SDK and proxy-booting legacy CircleCI tests to their tiers (#45758) 2026-10-11 00:17:21 -07:00
test_guardrail_registry.py feat(guardrails): opt-in Bedrock scan of tool-call arguments and tool descriptions as text (#52999) 2026-11-20 08:08:19 +00:00
test_init_guardrails.py fix(config): treat blank env values as unset so the proxy neither crash-loops nor silently drops a guardrail (#46341) 2026-10-14 12:49:31 -07:00
test_llm_as_a_judge.py fix(guardrails): mask reasoning text on /v1/responses output (#52504) 2026-11-19 01:25:06 -08:00
test_mcp_jwt_signer.py fix(mcp)!: forward the LiteLLM key when the admin configures it (#50604) 2026-11-10 20:51:34 -08:00
test_pillar_guardrails.py refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
test_prompt_security_guardrails.py fix(anthropic)!: send /v1/messages PDF documents to OpenAI-shaped providers as file parts (#47166) 2026-10-29 08:06:12 -07:00
test_qostodian_nexus_guardrail.py
test_usage_endpoints.py
test_usage_tracking.py feat(spend-logs): rust spend log ledger writer (#52163) 2026-11-20 16:31:04 -08:00