Skip to content

fix(models): raise GenerationError for streamed refusals - #1992

Open
nzinci wants to merge 1 commit into
dottxt-ai:mainfrom
nzinci:fix/streamed-refusals
Open

fix(models): raise GenerationError for streamed refusals#1992
nzinci wants to merge 1 commit into
dottxt-ai:mainfrom
nzinci:fix/streamed-refusals

Conversation

@nzinci

@nzinci nzinci commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

The sync and async stream paths for OpenAI, vLLM, and SGLang only looked at delta.content. If a provider returned a refusal together with content, Outlines yielded the content instead of raising the GenerationError used by non-streamed calls.

This checks the refusal before yielding content in all six paths. It uses getattr because older OpenAI SDK versions do not define the refusal field, and it leaves the existing first-choice behavior unchanged.

The tests cover refusal chunks that also contain content, empty choices, missing refusal attributes, and refusals in later choices.

Tests

  • uv run pytest -q tests/models/test_provider_exceptions.py -k refusal — 18 passed, 62 deselected
  • uv run pytest -q tests/models/test_openai.py tests/models/test_vllm.py tests/models/test_sglang.py -m 'not api_call' — 54 passed, 19 deselected
  • uv run pytest -q tests/models/test_provider_exceptions.py — 80 passed
  • Mypy over the five changed files — passed
  • Ruff and git diff --check — passed

Check refusal deltas before yielding content from OpenAI-compatible
streaming APIs. Keep first-choice behavior and support SDK versions that
do not define the refusal field.

Add sync and async coverage for OpenAI, vLLM, and SGLang.
@github-actions

Copy link
Copy Markdown

📚 Documentation preview: https://dottxt-ai.github.io/outlines/pr-preview/pr-1992/

Preview updates automatically with each commit.

@nzinci

nzinci commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Tests and coverage pass. The style check only fails because mypy cannot find urllib3 in two unchanged files; this is unrelated to this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant