litellm/tests/test_litellm/llms/openai
Mateo Wang 4f7b20ec10
fix(guardrails): skip streaming guardrail rounds that re-scan cleared output (#39386)
* fix(guardrails): skip streaming guardrail rounds that re-scan cleared output

Streaming guardrails scanned the finished answer twice at end of stream
whenever the chunk count landed on a multiple of the sampling rate, ran
sampled rounds whose payload was identical to the previous one, and on
/v1/messages could scan an empty text before the first content chunk.
Every redundant round is a paid guardrail provider call.

Each endpoint handler now exposes a scan key describing what a round
would hand to apply_guardrail (the text so far, plus tool calls once the
stream has ended), and the unified streaming hook skips a sampled or
end-of-stream round whose key equals the last scanned one or carries
nothing to scan yet. Rounds that carry tool calls are never skipped.

* test(guardrails): expect one end-of-stream scan when the terminal chunk is sampled

Update sampled cadence expectations and use tuple-backed scan state

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: yassin <yassin@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-02 18:25:28 -07:00
..
chat fix(guardrails): skip streaming guardrail rounds that re-scan cleared output (#39386) 2026-09-02 18:25:28 -07:00
completion test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
embeddings/guardrail_translation style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
evals test: cover volcengine responses and openai evals transformations 2026-07-27 12:57:21 -07:00
image_generation fix(otel): emit LLM Call spans for speech, image, moderation, ocr and transcription (#37752) 2026-08-22 11:11:21 -07:00
realtime test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
responses fix(guardrails): skip streaming guardrail rounds that re-scan cleared output (#39386) 2026-09-02 18:25:28 -07:00
speech test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
transcriptions test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
vector_store_files fix: encode upstream URL path identifiers 2026-04-29 22:02:39 -07:00
vector_stores fix: encode upstream URL path identifiers 2026-04-29 22:02:39 -07:00
videos fix(videos): forward uploaded source file on /v1/videos/edits to the provider 2026-08-24 15:34:21 -07:00
test_cost_calculation.py fix(transcription): stop a zero output rate from zeroing transcription cost (#36914) 2026-08-14 15:12:37 -07:00
test_data_residency.py feat(openai): apply regional-processing cost uplift for EU/US data residency (#28626) 2026-05-25 20:36:14 -07:00
test_gpt5_transformation.py fix(gpt-5): resolve temperature support from the model's default reasoning effort 2026-08-27 18:46:18 -07:00
test_is_model_gpt_5_model.py feat(models): add GPT-5.6 (sol/terra/luna) pricing and metadata (#32659) 2026-07-09 11:51:12 -07:00
test_o_series_transformation.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_openai_common_utils.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_openai_empty_response.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_openai_file_content_streaming.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_openai_image_edit_transformation.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_openai_workload_identity.py fix(openai): treat empty api_key as unset for WIF resolution 2026-08-31 19:55:29 +00:00
test_use_chat_completions_api_no_leak.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00