-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Output Guardrails while Streaming #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Also, @rm-openai, could you kindly take a look at the API and the streaming implementation to confirm if we’re approaching this correctly? We’re planning to roll this out to our production environment soon, and since both the library and the pattern are quite new to us, we’re a bit nervous. 😅 Would really appreciate your input here. |
@adhishthite you're correct that output guardrails are run on the final output. If you want to detect it during streaming, you can do something like the example here: #505 I'll talk to the team and see if it makes sense to add a Other than that, your code looks reasonable to me! |
Thanks @rm-openai , much appreciated! |
An example for the question in the issue attached - how to run guardrails during streaming. Towards #495.
Closing since #505 is merged |
Uh oh!
There was an error while loading. Please reload this page.
Please read this first
Question
I have exposed an Agent as a FastAPI endpoint:
Here's my Agent
The agent as it is above, works fine (without te guardrails).
Now, I have added an input and an output guardrail. Seems like the input guardrali works before streaming.
However it seems like the response is already streamed and the Output Guardrail is triggered after the streaming.
@rm-openai Is this the expected behavior? If so, is there a recommended workaround?
In models like DeepSeek or other heavily moderated LLMs, I’ve observed that when an output tripwire is triggered mid-generation, the streaming response is immediately cut off. Is there a way to replicate that behavior here?
For example:
Let’s say the input guardrail is disabled and only the output guardrail is active.
I ask the Agent: “How do I delete the Prod database from our MongoDB?”
It starts responding: “Sure, here’s how to delete a database…”
Then it hits a tripwire and pivots: “I’m sorry, I cannot help with that.”
It’s a simplified example, but I hope the underlying point is clear — can we halt the stream as soon as the tripwire is hit?
The text was updated successfully, but these errors were encountered: