tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Agentic AI > ADK Agent Testing > Testing ADK Agent Output JSON Schema Validation

Testing ADK Agent Output JSON Schema Validation

Author: Venkata Sudhakar

ADK agents that return structured data must be tested against a JSON schema to catch regressions where a tool or sub-agent silently drops required fields or changes a value type. ShopMax India uses JSON schema validation in CI to ensure that the order summary agent always returns a contract-compliant payload before it is consumed by the checkout service in Bangalore and Mumbai.

The jsonschema library provides validate() which raises ValidationError when a dict violates the schema. In ADK tests, the pattern is to call the tool function directly, capture its return value, and pass it through validate(). A separate parametrized test covers required fields, optional fields, and type constraints so that each rule is independently visible in the test report.

The example below defines an order summary tool, specifies its JSON schema, and runs three validation assertions covering required fields, type correctness, and an invalid payload that must be rejected.


It gives the following output,

Schema valid for order ORD-9001, total Rs 12999.0
3 passed in 0.18s

Store the JSON schema in a separate schemas/ directory and load it with json.load() in tests so that the contract is shared between the agent implementation and the consumer service. Use additionalProperties: false to catch unexpected fields early, and add a schema version field to the payload so that consumers can migrate gracefully when the contract evolves.


 
  


  
bl  br