Skip to content

Add cookbook: streaming output guardrails client-side handling#840

Open
mintlify[bot] wants to merge 2 commits into
mainfrom
mintlify/streaming-output-guardrails-1775146675
Open

Add cookbook: streaming output guardrails client-side handling#840
mintlify[bot] wants to merge 2 commits into
mainfrom
mintlify/streaming-output-guardrails-1775146675

Conversation

@mintlify
Copy link
Copy Markdown
Contributor

@mintlify mintlify Bot commented Apr 2, 2026

Summary

  • Adds a new cookbook guide under Use Cases for handling streaming output guardrail results on the client side
  • Covers how to capture hook_results from the final SSE chunk after [DONE], inspect verdicts, and implement client-side retry, fallback, content filtering, and logging patterns
  • Includes Python and Node code examples for all patterns, plus a combined approach
  • References the existing streaming responses guardrails docs

Changes

  • New file: guides/use-cases/streaming-output-guardrails.mdx
  • Updated: docs.json — added page to the Cookbooks > Use Cases navigation group

@mintlify
Copy link
Copy Markdown
Contributor Author

mintlify Bot commented Apr 2, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
portkey-docs 🟢 Ready View Preview Apr 2, 2026, 4:21 PM

from portkey_ai import AsyncPortkey
import asyncio

portkey = AsyncPortkey(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to pass the strict open ai compliance header here, same for the node example with portkey package


async for chunk in response:
# Check for hook_results in every chunk
if chunk.model_extra and chunk.model_extra.get("hook_results"):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional/suggestion] can wait for done chunk and then do this cleanly, but this is okay

Copy link
Copy Markdown
Member

@narengogi narengogi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this section only have python example?

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