Skip to content

docs: handle ValidationError in chat streaming example - #150

Merged
edenreich merged 1 commit into
mainfrom
docs/issue-147-20261004-1152
Oct 4, 2026
Merged

edenreich merged 1 commit into
mainfrom
docs/issue-147-20261004-1152

Conversation

@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

Summary

The chat example's streaming snippet claimed a role-only first chunk "validates fine" and only caught json.JSONDecodeError. The generated models are strict: ChatCompletionStreamResponseDelta.content has no default and ChatCompletionStreamChoice.finish_reason does not allow null, so such a chunk raises an uncaught pydantic.ValidationError out of the loop (the repo's own xfail test test_stream_response_delta_allows_missing_content asserts exactly that).

  • examples/chat/README.md: dropped the "validates fine" claim, replaced it with a note that a delta without content or a null finish_reason raises ValidationError, and the snippet now catches (json.JSONDecodeError, ValidationError) and skips the chunk - matching the root README.md "Streaming Content" example.
  • examples/chat/main.py: added a ValidationError handler so python main.py skips rejected chunks instead of crashing.

Docs-only change to an example - no SDK behavior or public API change, so no [DOCS] ticket and no downstream repo impact.

Tests run: none - pip install is not permitted in this sandbox, so black/isort/mypy/pytest could not run. The edits are whitespace- and import-ordering-consistent with the surrounding code and no library code changed.

Closes #147

@edenreich
edenreich merged commit d7e10e1 into main Oct 4, 2026
1 check passed
@edenreich
edenreich deleted the docs/issue-147-20261004-1152 branch October 4, 2026 11:54
inference-gateway-releaser Bot added a commit that referenced this pull request Oct 21, 2026
## [0.22.0](v0.21.1...v0.22.0) (2026-10-21)

### ✨ Features

* add deprecated include filter to model listing (sync schemas v1.4.1) ([#156](#156)) ([dc61111](dc61111))
* add WebWright provider with schemas v1.5.0 ([7fcdee3](7fcdee3))
* sync generated types with schemas v0.34.4 ([#144](#144)) ([4ac0019](4ac0019))
* sync generated types with schemas v1.2.0 ([#149](#149)) ([78d220f](78d220f))

### 👷 CI

* **deps:** bump actions/create-github-app-token ([#155](#155)) ([cc4787b](cc4787b))
* **deps:** bump actions/setup-node ([#153](#153)) ([4ae5aac](4ae5aac))

### 📚 Documentation

* **agents:** add code readability guidelines ([#141](#141)) ([86dfcb6](86dfcb6))
* **agents:** add code readability guidelines ([#148](#148)) ([839f7af](839f7af))
* handle ValidationError in chat stream example ([#150](#150)) ([d7e10e1](d7e10e1))

### 🔧 Miscellaneous

* **deps:** bump claude-code 2.1.280 -> 2.1.283 ([#142](#142)) ([37993d1](37993d1))
* **deps:** bump claude-code 2.1.283 -> 2.1.285 ([#146](#146)) ([49286f0](49286f0))
* **deps:** bump claude-code 2.1.285 -> 2.1.289 ([#151](#151)) ([57cf945](57cf945))
* **deps:** bump claude-code 2.1.289 -> 2.1.296 ([#157](#157)) ([8cc0acc](8cc0acc))
* **deps:** bump infer CLI v0.208.0 -> v0.218.0 ([#143](#143)) ([f02ecf7](f02ecf7))
* **deps:** bump infer CLI v0.218.0 -> v0.221.1 ([#145](#145)) ([f8ad720](f8ad720))
* **deps:** bump infer CLI v0.221.1 -> v0.226.0 ([#152](#152)) ([22686e1](22686e1))
* **deps:** bump infer CLI v0.226.0 -> v0.231.1 ([#158](#158)) ([ccd8c4e](ccd8c4e))
* sync generated types with schemas v1.2.2 ([#154](#154)) ([ff488ae](ff488ae))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.22.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DOCS] Chat example says role-only stream chunks validate, but the model rejects them

1 participant