> 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/rag-metrics/hallucination.md).

# Hallucination RAG Metric

**Objective**: This metric evaluates the overlap of facts between the Response and the Context. It penalises any fabricated, incorrect or contradictory facts mentioned in the Response that are not found in the Context.

**Required Parameters**: `Prompt`, `Response`, `Context`

**Interpretation**: A higher score indicates the model response was hallucinated.

<figure><img src="/files/8n0H5g2moTbZe0Ofvi8a" alt=""><figcaption></figcaption></figure>

**Code Execution:**

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

The "schema\_mapping" variable needs to be defined first and is a pre-requisite for evaluation runs. Learn how to set this variable [here](/ragaai-catalyst/on-premise-deployment/on-premise-deployment-for-gcp.md).

**Example**:

* Prompt: What is the capital of Brazil?
* Context: Brazil is the largest country in South America, known for its diverse culture and the Amazon rainforest. Its official language is Portuguese and its capital is Brasília.
* Response: The capital of Brazil is Rio de Janeiro, which is famous for its Copacabana beach, Christ the Redeemer statue, and vibrant carnival celebrations.
* *Metric Output*: {‘score’: 1, ‘reason’: ‘The capital of Brazil is Brasília, not Rio de Janeiro’}

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.raga.ai/ragaai-catalyst/ragaai-metric-library/rag-metrics/hallucination.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
