# Sentiment classifier — Claude XML example

> Classify customer reviews as positive, neutral, or negative with few-shot examples.
>
> Source: https://claudexml.com/examples/sentiment-classifier/ · Last updated 2026-05-25

Home / Examples / Sentiment classifier
    Classification · beginner

# Sentiment classifier

    Classify customer reviews as positive, neutral, or negative with few-shot examples.

    You have an inbound stream of free-text reviews and want a single sentiment label per item for routing or analytics.


## The prompt

    Copy this verbatim. Replace the `{{ … }}` placeholders with your values.


```xml
<instructions>
Classify the review's sentiment. Return exactly one of: positive, neutral, negative.
Return only the lowercase label, no punctuation, no explanation.
</instructions>

<examples>
  <example><input>Loved it, will be back!</input><output>positive</output></example>
  <example><input>It was fine.</input><output>neutral</output></example>
  <example><input>Total waste of money.</input><output>negative</output></example>
</examples>

<review>{{ review_text }}</review>
```


## Sample input


```xml
The food took 45 minutes to arrive cold.
```


## Expected output


```xml
negative
```


## Notes & tuning tips


- Calibration: include at least one example per output class; skew in examples → skew in outputs.
- Add a fourth class ("mixed") only if you need it — extra classes always hurt accuracy on the existing ones.
- For a production version, also ask for confidence and route low-confidence items to humans.


## What this example uses

    Tags: <instructions> <examples> <example>

    Patterns: few shot


## More like this


      classification
### Support ticket triage with priority and routing
Classify tickets by category, priority, and the team that should handle them — JSON output.

      classification
### Multi-label content tagging
Apply zero-to-many tags from a controlled vocabulary to an article.

      classification
### Toxicity grader with rubric
Score user-generated comments on a 0–3 toxicity scale with reasoning.




Cite this page

`Sentiment classifier. claudexml.com. https://claudexml.com/examples/sentiment-classifier/`
