Skip to content

Commit 9046577

Browse files
Add missing guardrail exception import to quickstart (openai#1161)
docs: add missing InputGuardrailTripwireTriggered import to quickstart example Fixes NameError when handling guardrail exceptions by including the required import in the docs.
1 parent 23404e8 commit 9046577

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

docs/quickstart.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ You can define custom guardrails to run on the input or output.
9797
from agents import GuardrailFunctionOutput, Agent, Runner
9898
from pydantic import BaseModel
9999

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

123124
```python
124125
from agents import Agent, InputGuardrail, GuardrailFunctionOutput, Runner
126+
from agents.exceptions import InputGuardrailTripwireTriggered
125127
from pydantic import BaseModel
126128
import asyncio
127129

@@ -166,11 +168,19 @@ triage_agent = Agent(
166168
)
167169

168170
async def main():
169-
result = await Runner.run(triage_agent, "who was the first president of the united states?")
170-
print(result.final_output)
171-
172-
result = await Runner.run(triage_agent, "what is life")
173-
print(result.final_output)
171+
# Example 1: History question
172+
try:
173+
result = await Runner.run(triage_agent, "who was the first president of the united states?")
174+
print(result.final_output)
175+
except InputGuardrailTripwireTriggered as e:
176+
print("Guardrail blocked this input:", e)
177+
178+
# Example 2: General/philosophical question
179+
try:
180+
result = await Runner.run(triage_agent, "What is the meaning of life?")
181+
print(result.final_output)
182+
except InputGuardrailTripwireTriggered as e:
183+
print("Guardrail blocked this input:", e)
174184

175185
if __name__ == "__main__":
176186
asyncio.run(main())

0 commit comments

Comments
 (0)