Add cookbook: streaming output guardrails client-side handling#840
Open
mintlify[bot] wants to merge 2 commits into
Open
Add cookbook: streaming output guardrails client-side handling#840mintlify[bot] wants to merge 2 commits into
mintlify[bot] wants to merge 2 commits into
Conversation
Generated-By: mintlify-agent
Contributor
Author
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
narengogi
reviewed
Apr 23, 2026
| from portkey_ai import AsyncPortkey | ||
| import asyncio | ||
|
|
||
| portkey = AsyncPortkey( |
Member
There was a problem hiding this comment.
you need to pass the strict open ai compliance header here, same for the node example with portkey package
narengogi
reviewed
Apr 23, 2026
|
|
||
| async for chunk in response: | ||
| # Check for hook_results in every chunk | ||
| if chunk.model_extra and chunk.model_extra.get("hook_results"): |
Member
There was a problem hiding this comment.
[optional/suggestion] can wait for done chunk and then do this cleanly, but this is okay
narengogi
reviewed
Apr 23, 2026
Member
narengogi
left a comment
There was a problem hiding this comment.
really nice, good touch with the client side handling patterns section
added some comments
|
|
||
| Each guardrail in `after_request_hooks` returns a `verdict` (boolean) and an array of `checks`. A guardrail's overall verdict is `true` only when **all** its checks pass. | ||
|
|
||
| ```python |
Member
There was a problem hiding this comment.
why does this section only have python example?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hook_resultsfrom the final SSE chunk after[DONE], inspect verdicts, and implement client-side retry, fallback, content filtering, and logging patternsChanges
guides/use-cases/streaming-output-guardrails.mdxdocs.json— added page to the Cookbooks > Use Cases navigation group