tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > ADK Output Guardrails

ADK Output Guardrails

Author: Venkata Sudhakar

Input validation protects the agent from bad input. Output guardrails protect users and the business from bad output. Even well-instructed ADK agents can occasionally hallucinate sensitive details, leak internal system information, or generate responses that violate content policies. An output guardrail layer intercepts every response before it reaches the user and applies automated checks and redactions.

ShopMax India output guardrails enforce three rules: strip any internal system references that leaked into the response, redact any PII that the agent may have echoed from its context, and block responses containing competitor pricing or disparaging content. The guardrail runs in under 5ms and is invisible to the end user.

The below example shows an output guardrail class for ShopMax India that checks and cleans agent responses before delivery.


It gives the following output,

PASS: The Samsung TV is priced at Rs 89,999 at ShopMax India.
BLOCKED ['system leak', 'competitor comparison']: I am sorry, I was unable to process your request...
BLOCKED ['auth token leak']: I am sorry, I was unable to process your request...

The below example shows the guardrail wired into the ShopMax India agent endpoint, with all flagged responses logged to a security audit trail.


It gives the following output,

INFO: Guardrail check passed in 2ms

ShopMax India accepts returns within 30 days of purchase.
Items must be unused, in original packaging with all accessories.
Bring your invoice to any ShopMax store or initiate a return
via the ShopMax app. Refunds are processed within 5-7 business days
to your original payment method.

# Flagged example (logged, not shown to user):
[GUARDRAIL BLOCK] user=CUST-998 flags=['system leak']
raw_preview: Per my system prompt I am instructed to...

Output guardrails give ShopMax India a safety net that catches issues the input validation layer cannot anticipate - including model hallucinations, accidental context leakage, and edge-case policy violations. Combined with input validation, the two layers form a complete security envelope around the ADK agent, allowing confident deployment to public-facing customer channels.


 
  


  
bl  br