> For the complete documentation index, see [llms.txt](https://docs.raga.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.raga.ai/ragaai-catalyst/ragaai-metric-library/guardrails/valid-json.md).

# Valid JSON

Ensure AI outputs produce correct JSON structure. Detect errors before data is processed or used.

**Objective**\
Checks if the text is a valid JSON format, ensuring proper data structure.

**Interpretation**\
A higher score indicates the text is not valid JSON. A lower (or zero) score indicates the response is valid JSON.

**Code Execution**

```python
metrics = [
    {
        "name": "Valid Json",
        "config": {
            "model": "gpt-4o-mini",
            "provider": "openai"
        },
        "column_name": "your-column-identifier",
        "schema_mapping": schema_mapping
    }
]
```

**Example**

* **Prompt**: “Provide a JSON object containing your name and age.”
* **Context**: “Must be valid JSON.”
* **Response**: `{"name": "Alice", "age": 30`
* **Metric Output**: `{"score": 1, "reason": "Invalid JSON format (missing closing brace)."}`
