> 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 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.

**`dataset`**

---

**`llm`** `= self.rails.llm`

---

**`llm_task_manager`** `= LLMTaskManager(self.rails_config)`

---

**`rails`** `= LLMRails(self.rails_config)`

---

**`rails_config`** `= RailsConfig.from_path(self.config_path)`

---

```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:**

**`prompt`** `str`

The prompt to generate extra responses for.

---

**`num_responses`** `int` — default: 2

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:**

**`config`** `str`

The path to the config folder.

---

**`data_path`** `str` — default: typer.Option('data/hallucination/sample.txt', help='Dataset path')

Dataset path.

---

**`num_samples`** `int` — default: typer.Option(50, help='Number of samples to evaluate')

Number of samples to evaluate.

---

**`output_dir`** `str` — default: typer.Option('outputs/hallucination', help='Output directory')

Output directory for predictions.

---

**`write_outputs`** `bool` — default: typer.Option(True, help='Write outputs to file')

Whether to write the predictions to a file.

---