> 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-csv.md).

# Valid CSV

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

**Objective**\
Validates if the text is in a proper CSV format, ensuring data integrity.

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

**Code Execution**

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

**Example**

* **Prompt**: “Provide a CSV of three fruit names and their colors.”
* **Context**: “The CSV must have two columns: Fruit,Color.”
* **Response**:

  ```
  mathematicaCopyApple, Red
  Banana Yellow
  Cherry, Red
  ```
* **Metric Output**: `{"score": 1, "reason": "Invalid CSV format (missing comma in second line)."}`
