From b9dab3bc053a6a8b593b34e0337f99904b54c751 Mon Sep 17 00:00:00 2001 From: slubbers-openai Date: Wed, 16 Jul 2025 15:55:11 -0700 Subject: [PATCH 1/2] docs: add missing InputGuardrailTripwireTriggered import to quickstart example Fixes NameError when handling guardrail exceptions by including the required import in the docs. --- docs/quickstart.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/quickstart.md b/docs/quickstart.md index 213d16e5d..01e4af191 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -95,8 +95,10 @@ You can define custom guardrails to run on the input or output. ```python from agents import GuardrailFunctionOutput, Agent, Runner +from agents.exceptions import InputGuardrailTripwireTriggered from pydantic import BaseModel + class HomeworkOutput(BaseModel): is_homework: bool reasoning: str @@ -122,6 +124,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 From 1b71192cf116bba9572a278f79103cbeed8c6418 Mon Sep 17 00:00:00 2001 From: slubbers-openai Date: Wed, 16 Jul 2025 16:23:34 -0700 Subject: [PATCH 2/2] docs: update quickstart to only import InputGuardrailTripwireTriggered where used and add try/except example --- docs/quickstart.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/quickstart.md b/docs/quickstart.md index 01e4af191..b5bc7177d 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -95,7 +95,6 @@ You can define custom guardrails to run on the input or output. ```python from agents import GuardrailFunctionOutput, Agent, Runner -from agents.exceptions import InputGuardrailTripwireTriggered from pydantic import BaseModel @@ -169,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())