> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.
> For full documentation content, see https://docs.nvidia.com/nemo/guardrails/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# nemoguardrails.evaluate.evaluate_hallucination

## Module Contents

### Classes

| Name                                                                                                           | Description                                                                       |
| -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| [`HallucinationRailsEvaluation`](#nemoguardrails-evaluate-evaluate_hallucination-HallucinationRailsEvaluation) | Helper class for running the hallucination rails evaluation for a Guardrails app. |

### Functions

| Name                                                           | Description                                              |
| -------------------------------------------------------------- | -------------------------------------------------------- |
| [`main`](#nemoguardrails-evaluate-evaluate_hallucination-main) | Main function to run the hallucination rails evaluation. |

### API

```python
class nemoguardrails.evaluate.evaluate_hallucination.HallucinationRailsEvaluation(
    config: str,
    dataset_path: str = 'data/hallucination/sample....,
    num_samples: int = 50,
    output_dir: str = 'outputs/hallucination',
    write_outputs: bool = True
)
```

Helper class for running the hallucination rails evaluation for a Guardrails app.
It contains all the configuration parameters required to run the evaluation.

```python
nemoguardrails.evaluate.evaluate_hallucination.HallucinationRailsEvaluation.get_extra_responses(
    prompt,
    num_responses = 2
)
```

Sample extra responses with temperature=1.0 from the LLM for hallucination check.

**Parameters:**

The prompt to generate extra responses for.

Number of extra responses to generate.

**Returns:**

List\[str]: The list of extra responses.

```python
nemoguardrails.evaluate.evaluate_hallucination.HallucinationRailsEvaluation.get_response_with_retries(
    prompt,
    max_tries = 1,
    llm_params = None
)
```

```python
nemoguardrails.evaluate.evaluate_hallucination.HallucinationRailsEvaluation.run()
```

Run  and print the hallucination rail evaluation.

```python
nemoguardrails.evaluate.evaluate_hallucination.HallucinationRailsEvaluation.self_check_hallucination()
```

Run the hallucination rail evaluation.
For each prompt, generate 2 extra responses from the LLM and check consistency with the bot response.
If inconsistency is detected, flag the prompt as hallucination.

**Returns:**

Tuple\[List\[HallucinationPrediction], int]: Tuple containing hallucination predictions and the number flagged.

```python
nemoguardrails.evaluate.evaluate_hallucination.main(
    config: str,
    data_path: str = typer.Option('data/hallucin...,
    num_samples: int = typer.Option(50, help='Numb...,
    output_dir: str = typer.Option('outputs/hallu...,
    write_outputs: bool = typer.Option(True, help='Wr...
)
```

Main function to run the hallucination rails evaluation.

**Parameters:**

The path to the config folder.

Dataset path.

Number of samples to evaluate.

Output directory for predictions.

Whether to write the predictions to a file.