Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add missing guardrail exception import to quickstart #1161

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

Merged
merged 3 commits into from
Jul 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ You can define custom guardrails to run on the input or output.
from agents import GuardrailFunctionOutput, Agent, Runner
from pydantic import BaseModel


class HomeworkOutput(BaseModel):
is_homework: bool
reasoning: str
Expand All @@ -122,6 +123,7 @@ Let's put it all together and run the entire workflow, using handoffs and the in

```python
from agents import Agent, InputGuardrail, GuardrailFunctionOutput, Runner
from agents.exceptions import InputGuardrailTripwireTriggered
from pydantic import BaseModel
import asyncio

Expand Down Expand Up @@ -166,11 +168,19 @@ triage_agent = Agent(
)

async def main():
result = await Runner.run(triage_agent, "who was the first president of the united states?")
print(result.final_output)

result = await Runner.run(triage_agent, "what is life")
print(result.final_output)
# Example 1: History question
try:
result = await Runner.run(triage_agent, "who was the first president of the united states?")
print(result.final_output)
except InputGuardrailTripwireTriggered as e:
print("Guardrail blocked this input:", e)

# Example 2: General/philosophical question
try:
result = await Runner.run(triage_agent, "What is the meaning of life?")
print(result.final_output)
except InputGuardrailTripwireTriggered as e:
print("Guardrail blocked this input:", e)

if __name__ == "__main__":
asyncio.run(main())
Expand Down