Principle:Guardrails ai Guardrails Structured Output Consumption
| Knowledge Sources | |
|---|---|
| Domains | Structured_Output, Data_Conversion |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
A consumption principle for converting validated structured output from a Guard execution into typed Python objects.
Description
Structured Output Consumption is the final step in the structured data generation pipeline. After a Guard validates structured JSON output, the ValidationOutcome.validated_output contains a Python dict (or list) that matches the Pydantic model's structure. The consumer can use this dict directly or re-instantiate the Pydantic model with MyModel(**outcome.validated_output) for type-safe access.
This principle addresses the gap between LLM-generated JSON (which is always a dict/list after parsing) and typed Python objects (which provide IDE support, validation, and serialization).
Usage
Apply this after any Guard execution with structured output. Always check validation_passed before consuming the output. For type-safe access, instantiate the Pydantic model from the dict.
Theoretical Basis
The consumption flow:
- Check status: Verify validation_passed is True
- Access dict: Use validated_output as a raw Python dict
- Optionally type: Instantiate Pydantic model for type safety: MyModel(**validated_output)