> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Obtaining Sentiment Analysis

> Guide to performing sentiment analysis using Amazon Bedrock, designing prompts, and operational workflows to classify feedback as positive negative or neutral for analytics and automation

In this lesson we'll cover how to perform sentiment analysis—automatically classifying text as positive, negative, or neutral—using Amazon Bedrock and a foundation model. We'll walk through the problem, a practical solution, and an operational workflow for reliable classification. Finally, we'll summarize expected results and key takeaways.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tDsOIcBSOgU8BE1P/images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/lecture-flow-sentiment-analysis-workflow.jpg?fit=max&auto=format&n=tDsOIcBSOgU8BE1P&q=85&s=1f07c18ce6e760f6fc30a0d68443427b" alt="A presentation slide titled &#x22;Lecture Flow&#x22; showing a three-step process: Problem → Solution → Workflow. The notes state manual customer sentiment is difficult, the solution is sentiment analysis, and the workflow focuses on classification, not generation." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/lecture-flow-sentiment-analysis-workflow.jpg" />
</Frame>

## Problem: high volumes of customer feedback

Companies collect feedback across many channels—customer reviews, support tickets, surveys, and social media—and that text contains early warning signs about product quality, service issues, and brand perception. Manually labeling thousands of entries is slow, inconsistent, and makes it difficult to spot trends or prioritize action quickly.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tDsOIcBSOgU8BE1P/images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/feedback-sources-customer-insights.jpg?fit=max&auto=format&n=tDsOIcBSOgU8BE1P&q=85&s=92f4dff18b22ff4e444ce8b2b4f5f6e7" alt="A slide titled &#x22;Real-World Problem&#x22; showing a central &#x22;Feedback&#x22; icon surrounded by four blue tiles labeled Customer reviews, Support tickets, Social media comments, and Survey responses. A purple banner at the bottom states that feedback contains valuable insights about how customers feel about products, services, or experiences." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/feedback-sources-customer-insights.jpg" />
</Frame>

The core requirement is simple: convert each feedback item into a discrete label (for example, "positive", "negative", or "neutral") so you can aggregate sentiment, detect changes, and take prioritized action at scale.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tDsOIcBSOgU8BE1P/images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/real-world-feedback-analysis-problems.jpg?fit=max&auto=format&n=tDsOIcBSOgU8BE1P&q=85&s=e2b0afbbfd3e121c4c2665353ace374c" alt="A presentation slide titled &#x22;Real-World Problem&#x22; with two colored panels: a blue card labeled &#x22;Slow & time-consuming&#x22; (showing a stopwatch/browser icon) and an orange card labeled &#x22;Hard to identify trends&#x22; (showing a chart icon) describing issues with manual feedback analysis and trend/sentiment detection." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/real-world-feedback-analysis-problems.jpg" />
</Frame>

## Solution overview: classification with a foundation model

Amazon Bedrock lets you call a foundation model to perform classification. For sentiment analysis you provide the feedback text plus an instruction prompt that constrains outputs to a small set of allowed labels. When the model is limited to those outputs, it returns a concise, consistent label that your application can parse and store.

Typical pipeline:

* Collect text inputs from reviews, tickets, or social channels.
* Send each text (or a batch) to the foundation model through Bedrock with a strict classification prompt.
* Parse and validate the single-label response and store it for dashboards, analytics, or automated ticket routing.

Example prompt (sent to the model):

```text theme={null}
Classify the following review as exactly one of: positive, negative, neutral.
Return only the label on a single line with no additional text.

Review:
"The product works well but the battery life is terrible."
```

Expected response:

```text theme={null}
negative
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tDsOIcBSOgU8BE1P/images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/sentiment-analysis-customer-review-negative.jpg?fit=max&auto=format&n=tDsOIcBSOgU8BE1P&q=85&s=d197da58f96418522cf37512b545a631" alt="A three-step diagram showing sentiment analysis: input is a customer review saying &#x22;The product works well but the battery life is terrible.&#x22; A foundation model processes the text and outputs a &#x22;Negative&#x22; sentiment label with a thumbs-down icon." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/sentiment-analysis-customer-review-negative.jpg" />
</Frame>

Benefits of this approach:

* Monitor satisfaction across thousands of items in near real time.
* Detect product regressions by tracking rising negative volume.
* Prioritize urgent tickets flagged with negative sentiment.
* Correlate sentiment shifts with releases, incidents, or campaigns.

## Why sentiment analysis is a classification task (not generation)

Sentiment analysis expects one of a small, predefined set of labels. This is different from generative tasks (summarization, open Q\&A, creative writing) where the model produces unconstrained text. For operational reliability, constrain the model to short, structured outputs—this improves consistency and simplifies downstream analytics.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tDsOIcBSOgU8BE1P/images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/not-generative-sentiment-classification.jpg?fit=max&auto=format&n=tDsOIcBSOgU8BE1P&q=85&s=0541305ea23926423ed17a1af968e4b2" alt="A slide titled &#x22;Solution: Not a Generative Task&#x22; explaining that sentiment analysis is a classification task, contrasting generative tasks (summarization, Q&A, writing) with classification (predefined labels, structured short responses)." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/not-generative-sentiment-classification.jpg" />
</Frame>

<Callout icon="lightbulb" color="#1CB2FE">
  Make the prompt explicit: list allowed labels and require the model to return only that label (for example, `positive`, `negative`, or `neutral`). Constraining the output to a predictable format makes automated storage and aggregation reliable.
</Callout>

## Prompt design principles

Well-designed prompts are essential for reliable classification. Use the three core principles below to reduce ambiguity and maximize repeatability.

| Principle | What to do | Example or note |
| - | -: | - |
| Define allowed categories | List the exact labels the model may return (e.g., positive, negative, neutral). | Use domain-specific labels if needed (e.g., `bug`, `feature-request`, `compliment`). |
| Specify output format | Require a single token or strict structure (single-line label, JSON object, or CSV). | Example JSON response: `{"label":"negative"}` — ensure the model returns precisely that. |
| Prevent extra explanation | Instruct the model not to add commentary, punctuation, or extra lines. | Provide a negative example and a positive example in few-shot format if helpful. |

Post-processing best practices:

* Validate the returned label is in your allowed set; if not, map to a fallback or retry the request.
* Normalize the label (lowercase, trim whitespace) before saving.
* Use regex or deterministic mapping to enforce format (e.g., `^(positive|negative|neutral)$`).
* For high-stakes use, consider a two-stage check: model + rule-based validator.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tDsOIcBSOgU8BE1P/images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/prompt-design-sentiment-workflow.jpg?fit=max&auto=format&n=tDsOIcBSOgU8BE1P&q=85&s=b55060e16c388bd3eaefd519cd5b9ff9" alt="An infographic titled &#x22;Workflow: Prompt Design for Sentiment&#x22; showing a colorful circular diagram that summarizes three key principles for sentiment classification prompts: define allowed categories, specify output format, and prevent extra explanation." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/prompt-design-sentiment-workflow.jpg" />
</Frame>

<Callout icon="warning" color="#FF6B6B">
  Be cautious with sensitive content and personally identifiable information (PII). Mask or remove PII before sending data to a model if required by policy. Also, validate model outputs because occasional misclassifications can occur—use sampling and human review for quality monitoring.
</Callout>

## Example scenarios

Here are sample reviews and their expected labels. These can be used as quick validation checks when designing prompts or testing model behavior.

| Review | Expected label |
| - | - |
| "Product setup was easy and it works perfectly." | `positive` |
| "Product is okay, but battery life is disappointing." | `negative` |
| "Product arrived yesterday and I haven't started using it." | `neutral` |

You can send these as individual prompts or batch them depending on throughput and Bedrock usage patterns. Always test a representative sample from each input channel (reviews, tickets, social posts) because language and tone vary by source.

## Expected results and operational benefits

Using Bedrock for sentiment classification gives organizations the ability to:

* Rapidly analyze very large volumes of feedback.
* Produce consistent, structured labels suitable for dashboards and analytics.
* Detect emerging negative trends faster and correlate them with product changes or incidents.
* Automate prioritization rules (e.g., escalate tickets labeled `negative` with keywords like `refund` or `broken`).

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tDsOIcBSOgU8BE1P/images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/results-organizational-benefits-feedback-trends.jpg?fit=max&auto=format&n=tDsOIcBSOgU8BE1P&q=85&s=4e1d9f7e167680448b6894adc72ef8ec" alt="A presentation slide titled &#x22;Results&#x22; showing four numbered panels of organizational benefits. Each panel lists a short benefit with an icon: analyze large volumes of feedback; identify trends; improve products and customer experience; and detect emerging issues earlier." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/results-organizational-benefits-feedback-trends.jpg" />
</Frame>

If you see a spike in negative labels, filter and inspect the underlying texts to find root causes and take corrective action quickly.

## Key takeaways

* Treat sentiment analysis as a classification problem: restrict outputs to a fixed set of labels and enforce strict formatting.
* Good prompt design (explicit allowed labels, exact output format, and prohibition of extra text) plus simple post-processing yields reliable labels for analytics and automation.
* Validate outputs, monitor model quality, and handle sensitive data according to your compliance policies.
* For more information on Bedrock and best practices, see the Amazon Bedrock documentation: [https://aws.amazon.com/bedrock/](https://aws.amazon.com/bedrock/)

This concludes the lesson on sentiment analysis.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/tDsOIcBSOgU8BE1P/images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/whats-next-code-generation-brain-icon.jpg?fit=max&auto=format&n=tDsOIcBSOgU8BE1P&q=85&s=70c828ec1182da1a4eb63c617a9cf427" alt="A presentation slide titled &#x22;What's Next? Understanding Code Generation.&#x22; On the right is a teal circular icon showing a stylized brain connected to circuit lines against a dark curved background." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Working-With-Different-Task-Types/Obtaining-Sentiment-Analysis/whats-next-code-generation-brain-icon.jpg" />
</Frame>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/introduction-to-amazon-bedrock/module/108362ba-e1ca-4ff5-ba48-8d7594429db7/lesson/14a905a5-a447-42b7-ad96-b691cb097660" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.