Skip to content

Handle OpenAI refusals and missing message content - #496

Open
malai001 wants to merge 3 commits into
google:mainfrom
malai001:fix/openai-refusal-handling
Open

Handle OpenAI refusals and missing message content#496
malai001 wants to merge 3 commits into
google:mainfrom
malai001:fix/openai-refusal-handling

Conversation

@malai001

@malai001 malai001 commented Jul 25, 2026

Copy link
Copy Markdown

Description

Fixes #491.

The realtime OpenAI provider previously returned
ScoredOutput(score=1.0, output=None) when message.content was
missing, causing refusal or content-filtered responses to be reported
as successful extractions.

This change aligns the realtime provider with the batch provider by:

  • Raising InferenceRuntimeError when message.content is None.
  • Surfacing the refusal reason when message.refusal is present.
  • Raising a descriptive error when neither content nor refusal is available.
  • Adding regression tests for successful responses, refusals, and missing-content responses.

How Has This Been Tested?

  • Added regression tests covering:
    • Successful completion
    • Refusal response (message.refusal)
    • Missing message.content
  • Ran:
python -m pytest tests/provider_schema_test.py

Result:

31 passed, 10 warnings

Checklist

  • I have read the contribution guidelines.
  • I have added or updated tests where appropriate.
  • I have verified that all tests pass locally.
  • My changes are limited to the scope of this fix.

@github-actions github-actions Bot added the size/S Pull request with 50-150 lines changed label Jul 25, 2026
@google-cla

google-cla Bot commented Jul 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@malai001
malai001 force-pushed the fix/openai-refusal-handling branch from 1e98e04 to f17989f Compare July 25, 2026 08:26
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Pull request with 50-150 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: OpenAI realtime path returns empty success (score=1.0, output=None) on a refusal / content-filtered response

1 participant