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

## Module Contents

### Functions

| Name                                                                                                                      | Description                                                                                                                                        |
| ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`_extract_harm_value`](#nemoguardrails-llm-output_parsers-_extract_harm_value)                                           | Helper function to extract harmful/unharmful value for a given field.                                                                              |
| [`_parse_unsafe_violations`](#nemoguardrails-llm-output_parsers-_parse_unsafe_violations)                                 | Helper function to parse violations from unsafe response.                                                                                          |
| [`_replace_prefix`](#nemoguardrails-llm-output_parsers-_replace_prefix)                                                   | Helper function to replace a prefix from a string.                                                                                                 |
| [`_strip_think_tags`](#nemoguardrails-llm-output_parsers-_strip_think_tags)                                               | Helper function to strip \<think>...\</think> tags from model response.                                                                            |
| [`bot_intent_parser`](#nemoguardrails-llm-output_parsers-bot_intent_parser)                                               | Parses the bot intent.                                                                                                                             |
| [`bot_message_parser`](#nemoguardrails-llm-output_parsers-bot_message_parser)                                             | Parses the bot messages.                                                                                                                           |
| [`is_content_safe`](#nemoguardrails-llm-output_parsers-is_content_safe)                                                   | Analyzes a given response from a guardrails check (e.g., content safety check or input check) and determines if the content is safe or not.        |
| [`nemoguard_parse_prompt_safety`](#nemoguardrails-llm-output_parsers-nemoguard_parse_prompt_safety)                       | Analyzes a given model response from a Guardrails check (e.g., content safety check or input check) and determines if the content is safe or not.  |
| [`nemoguard_parse_response_safety`](#nemoguardrails-llm-output_parsers-nemoguard_parse_response_safety)                   | Analyzes a given model response from a Guardrails check (e.g., content safety check or output check) and determines if the content is safe or not. |
| [`nemotron_reasoning_parse_prompt_safety`](#nemoguardrails-llm-output_parsers-nemotron_reasoning_parse_prompt_safety)     | Analyzes a response from Nemotron-Content-Safety-Reasoning-4B for prompt safety.                                                                   |
| [`nemotron_reasoning_parse_response_safety`](#nemoguardrails-llm-output_parsers-nemotron_reasoning_parse_response_safety) | Analyzes a response from Nemotron-Content-Safety-Reasoning-4B for response safety.                                                                 |
| [`user_intent_parser`](#nemoguardrails-llm-output_parsers-user_intent_parser)                                             | Parses the user intent.                                                                                                                            |
| [`verbose_v1_parser`](#nemoguardrails-llm-output_parsers-verbose_v1_parser)                                               | Parses completions generated using the `verbose_v1` formatter.                                                                                     |

### API

```python
nemoguardrails.llm.output_parsers._extract_harm_value(
    response: str,
    field_name: str
) -> str
```

Helper function to extract harmful/unharmful value for a given field.

**Parameters:**

The model response text (with think tags already stripped).

The field to look for (e.g., "Prompt harm" or "Response Harm").

**Returns:** `str`

The extracted value ("harmful" or "unharmful"), or "harmful" if parsing fails.

```python
nemoguardrails.llm.output_parsers._parse_unsafe_violations(
    response_text
)
```

Helper function to parse violations from unsafe response.

```python
nemoguardrails.llm.output_parsers._replace_prefix(
    s: str,
    prefix: str,
    repl: str
)
```

Helper function to replace a prefix from a string.

```python
nemoguardrails.llm.output_parsers._strip_think_tags(
    response: str
) -> str
```

Helper function to strip \<think>...\</think> tags from model response.

```python
nemoguardrails.llm.output_parsers.bot_intent_parser(
    s: str
)
```

Parses the bot intent.

```python
nemoguardrails.llm.output_parsers.bot_message_parser(
    s: str
)
```

Parses the bot messages.

```python
nemoguardrails.llm.output_parsers.is_content_safe(
    response: str
) -> typing.Sequence[typing.Union[bool, str]]
```

Analyzes a given response from a guardrails check (e.g., content safety check or input check) and determines if the content is safe or not.

The function operates based on the presence of certain keywords in the response:

* If the response contains "safe", the content is deemed safe.
* If the response contains "unsafe" or "yes", the content is deemed unsafe.
* If the response contains "no", the content is deemed safe.

Note: If you are using this function for a different task with a custom prompt, ensure to update the logic to match the new context.
Here, "yes" implies the content should be blocked, is unsafe, or violates a policy, while "no" implies the content is safe or does not violate any policy.

For example, in the `self_check_facts` action, we have a different interpretation.
Here, "yes" indicates the content is safe. This is against the default logic of the `is_content_safe` function.
Therefore, we invert the result of `is_content_safe` to align with this interpretation.
If `is_content_safe` returns `False` (content is safe), `result` will be `0.0`. If `is_content_safe` returns `True` (content is unsafe), `result` will be `1.0`.

**Parameters:**

The response string to analyze.

**Returns:** `Sequence[Union[bool, str]]`

Sequence\[Union\[bool, str]]: A sequence where the first element is a boolean indicating the safety of the content (True if safe, False otherwise),

```python
nemoguardrails.llm.output_parsers.nemoguard_parse_prompt_safety(
    response: str
) -> typing.Sequence[typing.Union[bool, str]]
```

Analyzes a given model response from a Guardrails check (e.g., content safety check or input check) and determines if the content is safe or not.

The function operates based on the following expected structured JSON output from the NemoGuard ContentSafety model.

\{
"User Safety": "unsafe",
"Violated Categories": "category1, category2"
}

**Parameters:**

The response string to analyze.

**Returns:** `Sequence[Union[bool, str]]`

Sequence\[Union\[bool, str]]: A sequence where the first element is a boolean indicating the safety of the content (True if safe, False otherwise),

```python
nemoguardrails.llm.output_parsers.nemoguard_parse_response_safety(
    response: str
) -> typing.Sequence[typing.Union[bool, str]]
```

Analyzes a given model response from a Guardrails check (e.g., content safety check or output check) and determines if the content is safe or not.

The function operates based on the following expected structured JSON output from the NemoGuard ContentSafety model.

\{
"User Safety": "unsafe",
"Response Safety": "unsafe",
"Violated Categories": "category1, category2"
}

**Parameters:**

The response string to analyze.

**Returns:** `Sequence[Union[bool, str]]`

Sequence\[Union\[bool, str]]: A sequence where the first element is a boolean indicating the safety of the content (True if safe, False otherwise),

```python
nemoguardrails.llm.output_parsers.nemotron_reasoning_parse_prompt_safety(
    response: str
) -> typing.Sequence[typing.Union[bool, str]]
```

Analyzes a response from Nemotron-Content-Safety-Reasoning-4B for prompt safety.

The function parses the following expected output format:

**Parameters:**

The response string to analyze.

**Returns:** `Sequence[Union[bool, str]]`

Sequence\[Union\[bool, str]]: A sequence where the first element is a boolean

```python
nemoguardrails.llm.output_parsers.nemotron_reasoning_parse_response_safety(
    response: str
) -> typing.Sequence[typing.Union[bool, str]]
```

Analyzes a response from Nemotron-Content-Safety-Reasoning-4B for response safety.

The function parses the following expected output format:

**Parameters:**

The response string to analyze.

**Returns:** `Sequence[Union[bool, str]]`

Sequence\[Union\[bool, str]]: A sequence where the first element is a boolean

```python
nemoguardrails.llm.output_parsers.user_intent_parser(
    s: str
)
```

Parses the user intent.

```python
nemoguardrails.llm.output_parsers.verbose_v1_parser(
    s: str
)
```

Parses completions generated using the `verbose_v1` formatter.