> 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/additional-metrics/guardrails/sentiment.md).

# Sentiment

Sentiment Guardrail is used to detect a prompt's sentiment and that the prompt has a sentiment score lower than the threshold. The scanner based on the NLTK's SentimentIntensityAnalyzer.

**Parameters**:

`data:`

* `prompt` (str): The prompt to scan for sentiment.

`arguments:`

* `threshold` (float, optional): Threshold for the sentiment score (from -1 to 1). Default is -0.1.

**Interpretation**

The sentiment score is calculated using nltk's Vader sentiment analyzer. The SentimentIntensityAnalyzer produces a sentiment score ranging from -1 to 1:

-1 represents a completely negative sentiment.

0 represents a neutral sentiment.

1 represents a completely positive sentiment.

**Example:**

```
pos_sentiment = "The book was good."

neutral_sentiment = "The plot was good, but the characters are uncompelling and the dialog is not great."

neg_sentiment = "A really bad, horrible book."

threshold = -0.1
```

`Results:`

```
pos_sentiment -> Passed , Score = 0.44

neutral_sentiment -> Failed, Score = -0.70

neg_sentiment -> Failed = -0.82
```

#### Code Example:

```python
`
pos_sentiment = "The book was good."
neutral_sentiment = "The plot was good, but the characters are uncompelling and the dialog is not great."
neg_sentiment = "A really bad, horrible book."
evaluator.add_test(
    test_names=["sentiment_guardrail"],
    data={
        "prompt": pos_sentiment
    }
    ).run()

evaluator.print_results()

```


---

# 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/additional-metrics/guardrails/sentiment.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.
