ai newsFr., 4. Dez.
EilmeldungAlibaba Releases Qwen4-35B-A3B: Open-Weight MoE Model With 1M Context

Prompt Engineering Explained: From "Just Ask AI" to Mastering the Art of Prompts 🚀

Most guides on prompt engineering throw a list of terms at you: zero-shot, few-shot, chain-of-thought, persona. Each one comes with its own unrelated example, making it hard to see how they connect or when to combine them. In this post, we do it differently. We take one simple prompt and upgrade it

dev.toMittwoch 20:12 · 02.12.8 Min. Lesezeit
Bild: dev.to

Posted on Dec 2 • Originally published at rishikesh-vedpathak.hashnode.dev

Most guides on prompt engineering throw a list of terms at you: zero-shot, few-shot, chain-of-thought, persona. Each one comes with its own unrelated example, making it hard to see how they connect or when to combine them.

In this post, we do it differently. We take one simple prompt and upgrade it step by step. Each technique builds on the previous one, so you can see exactly what changes and why it helps.

Imagine you run a small online store. You want an AI to read customer messages and tell you how the customer feels, so you can decide what to do next.

Here is the customer message we will use throughout:

"My order arrived two days late and the box was damaged, but the support agent who helped me was wonderful."

This message is deliberately tricky: it mixes complaints and praise in the same sentence. That makes it a great stress test for each technique.

What it is: You ask the model to do a task with no examples, just a plain instruction. The model relies entirely on what it already knows.

Classify the sentiment of this customer message. Message: "My order arrived two days late and the box was damaged, but the support agent who helped me was wonderful." Enter fullscreen mode Exit fullscreen mode Possible output:

Mixed Enter fullscreen mode Exit fullscreen mode When it works well: Simple, common tasks such as summarizing, translating, or basic classification.

The weakness: The model decides the answer format and labels on its own. Today it might say "Mixed", tomorrow "Neutral", and the next day write a full paragraph. You have no control over consistency.

What it is: You include one example (one-shot) or several examples (few-shot) of the task done right. The model learns the pattern by imitation.

Classify the sentiment of each customer message as Positive, Negative, or Mixed. Message: "Fast delivery and great packaging!" Sentiment: Positive Message: "The item stopped working after one day. Very disappointed." Sentiment: Negative Message: "The product is fine, but shipping took forever." Sentiment: Mixed Message: "My order arrived two days late and the box was damaged, but the support agent who helped me was wonderful." Sentiment: Enter fullscreen mode Exit fullscreen mode Output:

Mixed Enter fullscreen mode Exit fullscreen mode What changed: The model now knows the exact labels to use and the exact format to answer in. Showing examples is often faster and clearer than writing long formatting rules.

Tip: Use 2 to 5 varied examples. Cover different edge cases (positive, negative, and mixed) and keep the structure identical every time.

What it is: You ask the model to reason step by step before giving the final answer. Working through the logic out loud helps the model handle nuance and multi-part decisions.

(To keep the prompt compact while we test reasoning, we will set the examples aside for a moment and add a step-by-step instruction.)

Classify the sentiment of the customer message below as Positive, Negative, or Mixed. First, think step by step: 1. List what the customer is happy about. 2. List what the customer is unhappy about. 3. Decide which outweighs the other, or whether both matter. Then give the final answer on a new line starting with "Sentiment:". Message: "My order arrived two days late and the box was damaged, but the support agent who helped me was wonderful." Enter fullscreen mode Exit fullscreen mode Output:

1. Happy about: The support agent was wonderful. 2. Unhappy about: Late delivery (two days) and a damaged box. 3. There are two complaints about the delivery experience and one strong compliment about customer service. Neither cancels the other out. Sentiment: Mixed Enter fullscreen mode Exit fullscreen mode What changed: You can now see why the model chose its answer, making mistakes easy to spot. For harder problems like math, planning, or policy checks, this significantly improves accuracy. (Note: Newer "reasoning" models do much of this thinking automatically behind the scenes, though explicitly listing steps still lets you control what the model evaluates.)

Bonus - Few-shot CoT: You can combine steps 2 and 3 by providing examples that include the step-by-step reasoning, not just the final label.

What it is: You assign the model a specific role. The persona shapes its vocabulary, priorities, tone, and what details it flags as important.

You are a senior customer experience analyst at an e-commerce company. You care about spotting issues that could cause customers to leave. Classify the sentiment of the customer message below as Positive, Negative, or Mixed. First, think step by step: 1. List what the customer is happy about. 2. List what the customer is unhappy about. 3. Decide which outweighs the other, or whether both matter. Then give the final answer on a new line starting with "Sentiment:". Message: "My order arrived two days late and the box was damaged, but the support agent who helped me was wonderful." Enter fullscreen mode Exit fullscreen mode Output:

1. Happy about: High-quality, empathetic support interaction. 2. Unhappy about: Fulfillment delay (two days late) and damaged packaging. 3. While strong support prevented immediate frustration from boiling over, fulfillment failures create high churn risk if left unresolved. Both signals matter. Sentiment: Mixed Enter fullscreen mode Exit fullscreen mode What changed: Notice how the language shifted from casual summary to business analysis-framing the delivery issue as a churn risk and the support agent as a retention buffer.

Tip: Be specific. "Senior customer experience analyst who cares about churn risk" outperforms a generic "expert." Personas also control tone, such as "explain like a patient teacher" or "respond like a concise editor."

What it is: You give the model background information and strict boundaries. Context explains the situation; constraints define what to do and what to avoid.

You are a senior customer experience analyst at an e-commerce company. You care about spotting issues that could cause customers to leave. Context: We sell handmade ceramics.

Fragile items often break in transit, and we recently switched courier partners. Classify the sentiment of the customer message below as Positive, Negative, or Mixed. First, think step by step: 1.

List what the customer is happy about. 2. List what the customer is unhappy about.

3. Decide which outweighs the other, or whether both matter. Then give the final answer on a new line starting with "Sentiment:".

Constraints: Keep the reasoning under 60 words. Do not suggest compensation or refunds. Message: "My order arrived two days late and the box was damaged, but the support agent who helped me was wonderful." Enter fullscreen mode Exit fullscreen mode Output:

1. Happy about: Responsive, helpful support agent. 2. Unhappy about: Two-day delay and a damaged box—a major risk for fragile handmade ceramics following our recent courier switch. 3. Strong support saved the interaction, but transit damage threatens repeat business and must be flagged immediately. Sentiment: Mixed Enter fullscreen mode Exit fullscreen mode What changed: The model now understands why a damaged box is critical for a ceramics shop and connects it to the new courier. Meanwhile, the constraints keep the output tight and prevent unauthorized refund promises.

What it is: You require the model to return data in a strict, machine-readable layout such as JSON, CSV, or a Markdown table. This is essential when another program or spreadsheet will process the result.

(Notice how we replace the free-text reasoning lines with JSON fields, turning our chain-of-thought steps into structured data so the output stays valid JSON.)

You are a senior customer experience analyst at an e-commerce company. You care about spotting issues that could cause customers to leave. Context: We sell handmade ceramics. Fragile items often break in transit, and we recently switched courier partners. Analyze the customer message below. Return ONLY valid JSON matching this exact schema: { "positives": ["..."], "negatives": ["..."], "reasoning": "One brief sentence explaining the overall impact", "sentiment": "Positive | Negative | Mixed", "churn_risk": "Low | Medium | High" } Constraints: Keep "reasoning" under 30 words. Do not suggest compensation or refunds. Message: "My order arrived two days late and the box was damaged, but the support agent who helped me was wonderful." Enter fullscreen mode Exit fullscreen mode Output:

{ "positives": [ "Support agent was wonderful" ], "negatives": [ "Delivery was two days late", "Box arrived damaged" ], "reasoning": "Great support prevented immediate churn, but box damage poses a serious risk for fragile ceramics.", "sentiment": "Mixed", "churn_risk": "Medium" } Enter fullscreen mode Exit fullscreen mode What changed: The output is now completely predictable and ready for automation. You can pipe this straight into a database, dashboard, or alerting workflow without manual cleanup.

What it is: Instead of cramming every job into one giant prompt, you break the workflow into smaller, focused prompts where the output of one becomes the input of the next.

Here is an analysis of a customer message: {paste JSON from Prompt 1} Based on this, recommend one customer-facing follow-up action (such as checking if the ceramic item arrived intact or logging courier feedback) in one sentence. Do not offer refunds. Enter fullscreen mode Exit fullscreen mode Prompt 3 - Draft the reply: Feed that recommended action into a final prompt: Write a warm, 3-sentence reply to the customer.

Thank them for praising our support agent, apologize for the shipping delay and damaged box, and include this next step: {action from Prompt 2} Enter fullscreen mode Exit fullscreen mode What changed: Each prompt has a single, clear responsibility. It is easier to test, cheaper to debug, and much more reliable—if the customer reply sounds off, you only need to tweak Prompt 3 without breaking your data extraction in Prompt 1.

Here is how our single prompt evolved across all seven upgrades:

You do not need all seven techniques in every prompt. Start simple, inspect where the output falls short, and add one upgrade at a time to fix that specific gap. That habit of iterative refinement—not memorizing buzzwords—is the real skill behind prompt engineering.

Try it yourself: Take one prompt you use regularly at work today and upgrade it by just one or two steps from the list above.

Quelle: dev.to (dev.to). Original öffnen