You’ve probably noticed that asking an LLM to do something super complicated in one go often results in a confused mess. The trick isn’t about making the LLM smarter; it’s about making your prompts smarter by breaking down the complex task into smaller, manageable steps. This is prompt decomposition.

Let’s say you want to analyze a customer review, extract key sentiment, identify product features mentioned, and then suggest a response. Asking for all that at once is a recipe for disaster.

Instead, let’s build it step-by-step.

Step 1: Sentiment Analysis

Imagine we have this review: "The battery life on this new phone is amazing, lasts all day! But the camera quality in low light is really disappointing, photos are grainy."

Here’s how we’d prompt for just the sentiment:

Analyze the sentiment of the following customer review. Provide a single sentiment label: POSITIVE, NEGATIVE, or MIXED.

Review: "The battery life on this new phone is amazing, lasts all day! But the camera quality in low light is really disappointing, photos are grainy."

Sentiment:

The LLM should output: MIXED

Step 2: Feature Extraction

Now, let’s get the specific product features mentioned.

Identify the product features mentioned in the following customer review. List each feature as a separate item.

Review: "The battery life on this new phone is amazing, lasts all day! But the camera quality in low light is really disappointing, photos are grainy."

Features:

The LLM should output:

- Battery life
- Camera quality

Step 3: Detailed Aspect Sentiment

We can go deeper and get sentiment for each identified feature. This is where decomposition really shines.

Analyze the sentiment towards specific product features mentioned in the following customer review. For each feature, provide a sentiment label: POSITIVE, NEGATIVE, or NEUTRAL.

Review: "The battery life on this new phone is amazing, lasts all day! But the camera quality in low light is really disappointing, photos are grainy."

Features mentioned:
- Battery life
- Camera quality

Analysis:
- Battery life:
- Camera quality:

The LLM should output:

- Battery life: POSITIVE
- Camera quality: NEGATIVE

Step 4: Suggesting a Response

Finally, we can use all the preceding information to craft a targeted response. This is where you’d combine the outputs from the previous steps.

A customer left the following review: "The battery life on this new phone is amazing, lasts all day! But the camera quality in low light is really disappointing, photos are grainy."

The overall sentiment is MIXED.
Key features mentioned are: Battery life (POSITIVE), Camera quality (NEGATIVE).

Draft a polite and helpful response to this customer. Acknowledge both the positive and negative feedback.

Response:

The LLM might output:

Thank you for your detailed feedback! We're thrilled to hear you're impressed with the battery life – it's great that it lasts all day for you. We also appreciate you bringing the low-light camera performance to our attention. We're always working to improve our products, and your feedback on the camera quality is valuable as we move forward.

This step-by-step approach ensures each part of the task is handled with focused attention, leading to more accurate and useful outputs. It’s like building a complex machine by assembling individual, well-tested components rather than trying to forge the whole thing at once.

The real power of prompt decomposition comes from using the output of one LLM call as the input for the next. This creates a chain of reasoning, where each step builds upon the last, mimicking a multi-stage thought process.

What most people don’t realize is that you can even use different LLM models for different steps if they excel at specific tasks. For instance, a smaller, faster model might be perfect for initial sentiment labeling, while a larger, more powerful model could handle the nuanced response generation. This isn’t about "chaining" in a formal framework; it’s about programmatically orchestrating LLM calls with carefully crafted inputs and outputs.

Once you’ve mastered decomposition, you’ll naturally start thinking about how to handle errors and edge cases within these chains, leading you into the world of agents and tool use.

Want structured learning?

Take the full Prompt-engineering course →