> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Faithfulness

> Learn how to use the faithfulness test

## Definition

The faithfulness test measures the factual consistency of the generated answer against the given context. This metric is based on the Ragas [faithfulness](https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/faithfulness/) metric.

## Taxonomy

* **Task types**: LLM.
* **Availability**: development (Continuously evaluate your models and datasets as you iterate on their versions.)
  and monitoring (Monitor a model in production, measure its health, check for drifts and set up alerts.).

## Why it matters

* Faithfulness ensures that your LLM generates responses that are consistent with the provided context and doesn't hallucinate information.
* This metric helps identify when your model is making up facts or contradicting the given context.
* It's essential for RAG (Retrieval-Augmented Generation) systems where the model should stay grounded in the provided information.

## Required columns

To compute this metric, your dataset must contain the following columns:

* **Outputs**: The generated answer/response from your LLM
* **Context**: The provided context or background information

> [!NOTE]
>
> This metric relies on an LLM evaluator judging your submission. On Openlayer,
> you can configure the underlying LLM used to compute it. Check out the
> [OpenAI](https://docs.openlayer.com/integrations/openai.md#openai-llm-evaluator) or
> [Anthropic](https://docs.openlayer.com/integrations/anthropic.md#anthropic-llm-evaluator) integration
> guides for details.

## Test configuration examples

If you are writing a `tests.json`, here are a few valid configurations for the faithfulness test:

```json Development theme={null}
[
  {
    "name": "Faithfulness above 0.9",
    "description": "Ensure that generated responses are faithful to the provided context with a score above 0.9",
    "type": "performance",
    "subtype": "metricThreshold",
    "thresholds": [
      {
        "insightName": "metrics",
        "measurement": "faithfulness",
        "operator": ">",
        "value": 0.9
      }
    ],
    "subpopulationFilters": null,
    "mode": "development",
    "usesValidationDataset": true,
    "usesTrainingDataset": false,
    "usesMlModel": true,
    "syncId": "b4dee7dc-4f15-48ca-a282-63e2c04e0689"
  }
]
```

```json Monitoring theme={null}
[
  {
    "name": "Faithfulness above 0.9",
    "description": "Ensure that generated responses are faithful to the provided context with a score above 0.9",
    "type": "performance",
    "subtype": "metricThreshold",
    "thresholds": [
      {
        "insightName": "metrics",
        "measurement": "faithfulness",
        "operator": ">",
        "value": 0.9
      }
    ],
    "subpopulationFilters": null,
    "mode": "monitoring",
    "usesProductionData": true,
    "evaluationWindow": 3600,
    "delayWindow": 0,
    "syncId": "b4dee7dc-4f15-48ca-a282-63e2c04e0689"
  }
]
```

## Related

* [Ragas integration](https://docs.openlayer.com/integrations/ragas.md) - Learn more about Ragas metrics.
* [Context utilization test](https://docs.openlayer.com/tests/catalog/context-utilization.md) - Evaluate how well context is used.
* [Answer correctness test](https://docs.openlayer.com/tests/catalog/answer-correctness.md) - Measure factual accuracy against ground truth.
* [Correctness test](https://docs.openlayer.com/tests/catalog/correctness.md) - Measure overall correctness of answers.
* [Aggregate metrics](https://docs.openlayer.com/tests/performance/aggregate-metrics) - Overview of all available metrics.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.