OpenAI Agents SDK Prompt Injection: Guard Every Workflow Boundary
OpenAI Agents SDK guardrails run at defined workflow boundaries. Input guardrails cover the first agent, output guardrails cover the final agent, and tool guardrails cover guarded function calls. Prompt-injection controls need to follow those boundaries and govern each routed model request.

OpenAI's Agents SDK attaches guardrails to specific points in a workflow. According to the current guardrails documentation, the first agent receives the input check. The final agent receives the output check, while guarded function-tool calls use their own controls. A multi-agent chain can therefore cross several handoffs while a single first-input check remains far behind it.
TL;DR
- OpenAI Agents SDK guardrails have defined execution boundaries; map each one before relying on it.
- Reassemble and inspect the prompt at every model call after retrieval and whenever handoffs or tool output change the context.
- Keep tool execution policy separate from HTTP LLM request policy, then correlate both records.
The first input is only one input surface
A customer message may begin the run, but later context can arrive through retrieval, an MCP result, a function response, memory, or a specialist-agent handoff. Each addition can carry instructions that the first input guardrail never saw. The OpenAI documentation makes this workflow boundary explicit.
That is why a diagram with one green shield beside the user textbox gives false comfort. By the third handoff, the prompt on the wire may contain a system instruction, two summaries, a tool result, and a retrieved document. The original sentence is a thin strip near the bottom of a much larger context window.
A useful design starts with AI agent observability, then adds a policy decision at each routed model call. Tracing tells you where the context changed. Enforcement decides if the assembled request may leave.
Parallel guardrails change the timing
The SDK supports blocking and parallel guardrail execution. Its documentation states that blocking execution can stop the expensive model before it starts, while parallel execution may allow the model call to begin before the guardrail finishes.
For prompt-injection checks that must prevent transmission, run the decision before the model request. Parallel execution fits advisory checks where a late tripwire remains useful. It is a poor fit for secrets and regulated data, especially when a policy promises the request never reaches the provider.
I would rather add visible latency than write an incident report explaining that the classifier returned twelve milliseconds after the prompt left. Prevention needs ordering, not optimism.
Handoffs require a fresh assembled-context check
A handoff changes the active instructions and often changes the model. Treat that transition as a new request, even when the SDK keeps it inside one logical run. Bind the decision to the initiating user, source agent, destination agent, model route, data class, and current context hash.
OpenAI's safety guidance recommends moderation, red teaming, human review, and constrained inputs and outputs. Those practices reduce exposure. The request policy still needs deterministic rules for destination, identity, and data handling.
This complements AI agent tool scoping. Model-call policy controls what reaches the LLM. Tool policy controls what the agent may do after the model responds.
Tool output is untrusted context
Function tools and MCP tools can return text that looks like instructions. The next model call may place that text beside trusted developer messages. Preserve provenance labels when assembling the prompt, and classify the complete payload rather than the user's opening message alone.
For each call, record the run ID, handoff chain, tool-output sources, model, prompt hash, policy version, and decision. When an incident crosses three agents, that record turns a chat transcript into a sequence an investigator can reproduce.
DeepInspect
DeepInspect can govern authenticated HTTP requests from an Agents SDK deployment to LLM endpoints. The application supplies identity and route context; DeepInspect evaluates the assembled prompt against destination policy before the call reaches the model.
SDK handoffs, local code, and tool execution retain their own owners. The proxy record covers the model request and response, which can then be correlated with SDK traces and tool-authorization events.
Book a technical deep dive at deepinspect.ai.
Frequently asked questions
- Do SDK input guardrails run for every agent?
The current OpenAI Agents SDK documentation says input guardrails run only for the first agent in a chain. Teams that need checks around later custom function tools should use tool guardrails, and teams governing model transmission should inspect each assembled model request.
- Does prompt filtering control tool execution?
Prompt filtering can detect or classify suspicious text. Tool authorization decides if a named agent may invoke a specific operation with specific arguments. Keep the two decisions separate and link them with one run identifier.