Overview
Guardrails run on every node execution — checking input before it reaches the LLM and validating (or transforming) output before it is written to the context. By default, theinjection guardrail is active on all agents. You can configure guardrails at the workflow level, per agent, or disable them entirely.
Built-in Guardrails
injection
Detects common prompt-injection patterns in both input and output text.
If an injection signature is detected, the node fails immediately with a GuardrailViolation and the workflow status is set to "failed".
Detected patterns include:
ignore previous instructionsdisregard your instructionsyou are now [role]forget your instructionsnew instructions:override previous instructionsact as a [role]pretend you are [role]your new role issystem: you are
injection.
length
Limits the length of LLM output. In the default "truncate" mode, responses longer than the limit are silently cut and appended with "...".
The
length guardrail only checks output — input is passed through unchanged.pii
Detects personally identifiable information in both input and output text and either redacts it, blocks the call, or passes it through with a flag. Supported entities are email, phone, ssn, and credit_card. Credit-card matches are filtered through the Luhn checksum to suppress false positives.
Configuration:
Behavior:
- Input: Inspected before the prompt is sent to the LLM.
- Output: Inspected after the response is received, before downstream nodes see it.
- On
action: "block": RaisesPIIDetectedError(aGuardrailErrorsubclass) listing the entity types that matched.
schema
Validates LLM output against a JSON Schema Draft 7 definition. The guardrail parses the output text as JSON and checks it against the provided schema. Input text is passed through unchanged.
Use this guardrail when you need the LLM to produce structured JSON output that conforms to a specific schema — for example, extracting data into a fixed set of fields.
Configuration:
The schema guardrail requires a name and a config dict with a schema key:
- Input: Passed through unchanged.
- Output: Parsed as JSON and validated against the schema.
- On failure: Raises a
GuardrailViolationwith a message indicating the path and constraint that failed (e.g.,Schema violation at "$.age": 25 is greater than the maximum of 20).
cost_cap
Enforces token and/or USD budget ceilings on a workflow. After each node executes, the guardrail checks cumulative token usage and estimated cost. On exceedance, it either aborts the workflow or logs a warning.
At least one of max_usd or max_tokens must be specified.
Behavior:
- Input/Output: Both are pass-throughs; the guardrail only examines budget state.
- Budget checking: Runs after each node completes. Available to
when:conditions as_budget.total_tokensand_budget.estimated_usd. - On
action: "abort": RaisesBudgetExceededErrorwith details of the violation; the workflow transitions to"failed"status. - On
action: "warn": Logs a structured warning and allows execution to continue.
The
cost_cap guardrail works best when pricing information is available for your LLM models. If no pricing is found, estimated_usd will be None and only the max_tokens ceiling will be enforced.Configuration
Workflow-level (default for all agents)
guardrails is omitted from the workflow file, only injection is active.
Per-agent override
An agent’sguardrails field completely replaces the workflow-level list for that agent:
Disabling all guardrails
Set an empty list to disable all guardrails for the workflow or a specific agent:Execution Trace
Guardrails that pass are recorded in each node’s trace entry:GuardrailViolation sets the node’s error field and the workflow summary.status to "failed":