Skip to content

Commit 6cb57b8

Browse files
authored
Added openai agent sdk guardrails docs (#2100)
1 parent 7c791dd commit 6cb57b8

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@
325325
"guides/example-projects/claude-thinking-chatbot",
326326
"guides/example-projects/human-in-the-loop-workflow",
327327
"guides/example-projects/meme-generator-human-in-the-loop",
328+
"guides/example-projects/openai-agent-sdk-guardrails",
328329
"guides/example-projects/realtime-csv-importer",
329330
"guides/example-projects/realtime-fal-ai",
330331
"guides/example-projects/turborepo-monorepo-prisma",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: "OpenAI Agent SDK guardrails examples"
3+
sidebarTitle: "OpenAI Agent SDK guardrails"
4+
description: "This example project demonstrates how to implement different types of guardrails using the OpenAI Agent SDK with Trigger.dev for AI safety and control."
5+
---
6+
7+
import RealtimeLearnMore from "/snippets/realtime-learn-more.mdx";
8+
9+
<Info>The OpenAI Agent SDK is a Python library. </Info>
10+
11+
## Overview
12+
13+
This demo is a practical guide that demonstrates:
14+
15+
- **Three types of AI guardrails**: Input validation, output checking, and real-time streaming monitoring
16+
- Integration of the [OpenAI Agent SDK](https://openai.github.io/openai-agents-python/) with [Trigger.dev](https://trigger.dev) for production AI workflows
17+
- **Educational examples** of implementing guardrails for AI safety and control mechanisms
18+
- Real-world scenarios like math tutoring agents with content validation and complexity monitoring
19+
20+
Guardrails are safety mechanisms that run alongside AI agents to validate input, check output, monitor streaming content in real-time, and prevent unwanted or harmful behavior.
21+
22+
## GitHub repo
23+
24+
<Card
25+
title="View the OpenAI Agent SDK Guardrails repo"
26+
icon="GitHub"
27+
href="https://github.com/triggerdotdev/examples/tree/main/openai-agent-sdk-guardrails-examples"
28+
>
29+
Click here to view the full code for this project in our examples repository on GitHub. You can
30+
fork it and use it as a starting point for your own project.
31+
</Card>
32+
33+
## Video
34+
35+
<video
36+
controls
37+
className="w-full aspect-video"
38+
src="https://github.com/user-attachments/assets/9b1e55c7-467d-4aca-8b4a-a018014c0827"
39+
></video>
40+
41+
## Relevant code
42+
43+
### Trigger.dev Tasks
44+
45+
- **[inputGuardrails.ts](https://github.com/triggerdotdev/examples/blob/main/openai-agent-sdk-guardrails-examples/src/trigger/inputGuardrails.ts)** - Passes user prompts to Python script and handles `InputGuardrailTripwireTriggered` exceptions
46+
- **[outputGuardrails.ts](https://github.com/triggerdotdev/examples/blob/main/openai-agent-sdk-guardrails-examples/src/trigger/outputGuardrails.ts)** - Runs agent generation and catches `OutputGuardrailTripwireTriggered` exceptions with detailed error info
47+
- **[streamingGuardrails.ts](https://github.com/triggerdotdev/examples/blob/main/openai-agent-sdk-guardrails-examples/src/trigger/streamingGuardrails.ts)** - Executes streaming Python script and parses JSON output containing guardrail metrics
48+
49+
### Python Implementations
50+
51+
- **[input-guardrails.py](https://github.com/triggerdotdev/examples/blob/main/openai-agent-sdk-guardrails-examples/src/python/input-guardrails.py)** - Agent with `@input_guardrail` decorator that validates user input before processing (example: math tutor that only responds to math questions)
52+
- **[output-guardrails.py](https://github.com/triggerdotdev/examples/blob/main/openai-agent-sdk-guardrails-examples/src/python/output-guardrails.py)** - Agent with `@output_guardrail` decorator that validates generated responses using a separate guardrail agent
53+
- **[streaming-guardrails.py](https://github.com/triggerdotdev/examples/blob/main/openai-agent-sdk-guardrails-examples/src/python/streaming-guardrails.py)** - Processes `ResponseTextDeltaEvent` streams with async guardrail checks at configurable intervals (example: stops streaming if language is too complex for a 10-year-old)
54+
55+
### Configuration
56+
57+
- **[trigger.config.ts](https://github.com/triggerdotdev/examples/blob/main/openai-agent-sdk-guardrails-examples/trigger.config.ts)** - Uses the Trigger.dev Python extension
58+
59+
### Learn more
60+
61+
- [OpenAI Agent SDK documentation](https://openai.github.io/openai-agents-python/)
62+
- [OpenAI Agent SDK guardrails](https://openai.github.io/openai-agents-python/guardrails/)
63+
- Our [Python build extension](/config/extensions/pythonExtension#python)

docs/guides/introduction.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Example projects are full projects with example repos you can fork and use. Thes
4848
| [Batch LLM Evaluator](/guides/example-projects/batch-llm-evaluator) | Evaluate multiple LLM models and stream the results to the frontend. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/batch-llm-evaluator) |
4949
| [Claude thinking chatbot](/guides/example-projects/claude-thinking-chatbot) | Use Vercel's AI SDK and Anthropic's Claude 3.7 model to create a thinking chatbot. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/claude-thinking-chatbot) |
5050
| [Human-in-the-loop workflow](/guides/example-projects/human-in-the-loop-workflow) | Create audio summaries of newspaper articles using a human-in-the-loop workflow built with ReactFlow and Trigger.dev waitpoint tokens. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/article-summary-workflow) |
51+
| [OpenAI Agent SDK guardrails](/guides/example-projects/openai-agent-sdk-guardrails) | Use the OpenAI Agent SDK to create a guardrails system for your AI agents. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/openai-agent-sdk-guardrails-examples) |
5152
| [Python web crawler](/guides/python/python-crawl4ai) | Use Python, Crawl4AI and Playwright to create a headless web crawler with Trigger.dev. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/python-crawl4ai) |
5253
| [Realtime CSV Importer](/guides/example-projects/realtime-csv-importer) | Upload a CSV file and see the progress of the task streamed to the frontend. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/realtime-csv-importer) |
5354
| [Realtime Fal.ai image generation](/guides/example-projects/realtime-fal-ai) | Generate an image from a prompt using Fal.ai and show the progress of the task on the frontend using Realtime. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/realtime-fal-ai-image-generation) |

0 commit comments

Comments
 (0)