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

ADK Agent Guardrails

Author: Venkata Sudhakar

ADK Agent Guardrails are policies that control what an agent is allowed to do - restricting input topics, enforcing output formats, blocking harmful content, and preventing scope creep. ShopMax India applies guardrails to its customer service agents to ensure they stay on topic and never expose sensitive business data.

Guardrails in ADK are implemented through the agent instruction, input validation tools, and output inspection callbacks. A before-model callback can reject out-of-scope requests, while an after-model callback can sanitise or block responses that violate policy.

The below example shows an ADK agent with input guardrails that rejects requests outside the customer service scope.


It gives the following output,

Agent initialized: shopmax_support
Before-model callback registered: check_scope

The below example shows an output guardrail that strips any accidental exposure of internal order margin data from agent responses.


It gives the following output,

Agent ready with input and output guardrails.

Test - Off-topic query "What is Flipkart selling?":
> I can only assist with ShopMax India orders, products, and customer service. How can I help you?

Test - Valid query "Where is my order ORD-5521?":
> Your order ORD-5521 is currently out for delivery and will arrive by 6 PM today in Hyderabad.

ShopMax India applies guardrails across all customer-facing agents. Input guardrails prevent scope drift and protect against prompt injection. Output guardrails ensure that no internal pricing, margin, or supplier data ever appears in customer-facing responses - keeping the business compliant with data handling policies.


 
  


  
bl  br