---
title: "Structured Output Guardrail"
type: "guardrail"
provider: "community"
category: "safety"
source: "https://github.com/guardrails-ai/guardrails"
license: "Apache-2.0"
tags: ["validation", "json", "schema", "output"]
dateAdded: "2026-06-09"
origin: "community"
language: "en"
description: "Constrains a model to emit valid, schema-conformant JSON and specifies what to do when validation fails — reask, repair, or refuse."
---

Use this guardrail to make model output machine-safe.

## Contract

- Respond with **JSON only** — no prose, no code fences, no trailing commentary.
- The JSON must conform exactly to this schema:

```json
{
  "type": "object",
  "required": ["answer", "confidence"],
  "properties": {
    "answer": { "type": "string" },
    "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
    "sources": { "type": "array", "items": { "type": "string" } }
  },
  "additionalProperties": false
}
```

## On validation failure

If you cannot produce valid output (missing data, the question is unanswerable),
return `{"answer": "", "confidence": 0}` rather than inventing fields or values.
Do not include keys that are not in the schema.
