How guardrails work
Guardrails run in two stages:- Before-agent checks run on the user’s message before the agent sees it. Use these to block or filter inputs.
- After-agent checks run on the agent’s response before it’s shown. Use these to catch problems in the output.
Before-agent guardrails
PII detection & masking
Automatically detects personally identifiable information in the user’s message and handles it before the agent processes it. Detection patterns — choose which types of PII to look for:
Action — what to do when PII is detected:
Off-topic detection
Checks whether the user’s question falls within the topics you want this agent to handle. If the message is off-topic, the agent won’t run — it returns a message telling the user what the agent is for. When you add this guardrail, you define the allowed topics. These are plain-language descriptions, not rigid keywords: Example allowed topics:- Business data analysis
- Campaign performance
- Budget tracking
- Google Ads metrics
Jailbreak detection
Automatically detects attempts to override the agent’s instructions or make it behave outside its intended purpose (e.g. “ignore your system prompt and…”). No configuration needed — enable it and it runs automatically.Harmful content moderation
Checks for harmful, abusive, or unsafe content in the user’s message. Automatically blocks requests that contain hate speech, threats, or other harmful language. No configuration needed.After-agent guardrails
PII detection & masking (output)
The same PII detection applies to the agent’s response before it’s shown to the user. Useful when your data contains personal information that might appear in query results — for example, if a table includes customer email addresses that could be returned by a query.Hallucination detection
Checks the agent’s response for claims that don’t appear to be grounded in the data it retrieved. If the agent makes a statement that can’t be verified from the query results, this guardrail flags or blocks the response. No configuration needed — enable it and it runs on every response automatically.Custom guardrails
Custom guardrails let you define your own checks using plain language. You write a prompt that describes the rule, and the AI evaluates each message or response against it. Each custom guardrail has:
Custom guardrails can be added to either the before-agent or after-agent stage.
Example custom guardrail:
Name: Budget guardrail
Prompt: Does this response recommend increasing any budget by more than 50% compared to current spend?
Action: Warn
Custom guardrails use an AI call to evaluate each message, which adds a small amount of processing time and cost per request. Use them for checks that matter most — not as a catch-all.