Rewrite Weak Prompts with Zero-Shot, Few-Shot, and Chain-of-Thought Priya Nair published a tutorial showing developers how to rewrite weak prompts into stable classifiers using zero-shot, few-shot, and chain-of-thought patterns, with runnable Python code verified against the Anthropic SDK 1.4.0 and the claude-opus-5 model. The guide demonstrates turning a vague support-ticket prompt into parseable category labels by adding explicit rules, examples, and visible reasoning, addressing common prompt engineering failures. Rewrite Weak Prompts with Zero-Shot, Few-Shot, and Chain-of-Thought Turn one vague prompt into a stable, parseable classifier using three prompting patterns, in runnable Python. Priya Nair https://sourcefeed.dev/u/priya nair What you'll build A single Python script that takes one vague, unreliable prompt and rewrites it three ways: zero-shot with explicit instructions, few-shot with examples, and chain-of-thought with visible reasoning. You'll run all four against the same ambiguous support ticket and watch the output go from chatty prose to a stable, parseable label. Prerequisites - Python https://www.python.org/ 3.10 or newer python3 --version . The Anthropic SDK requires 3.10+. - An Anthropic API key from the Claude Console https://platform.claude.com/settings/keys , with a few cents of credit on the account. - Verified against the anthropic https://pypi.org/project/anthropic/ Python SDK 1.4.0 and model claude-opus-5 on macOS; Linux is identical, and on Windows use .venv\Scripts\activate instead of source . 1. Set up the project mkdir prompt-patterns && cd prompt-patterns python3 -m venv .venv && source .venv/bin/activate pip install anthropic export ANTHROPIC API KEY="your-api-key-here" The SDK reads ANTHROPIC API KEY from the environment, so the code never touches the key directly. 2. Start with the weak prompt Create prompts.py . The task: route support tickets into one of four categories. The test ticket is deliberately ambiguous, since it's half billing complaint and half how-to question. python import anthropic client = anthropic.Anthropic TICKET = "I got charged twice this month. Also, how do I export my invoices to CSV?" def ask prompt: str - str: response = client.messages.create model="claude-opus-5", max tokens=1024, messages= {"role": "user", "content": prompt} , return "".join b.text for b in response.content if b.type == "text" .strip weak = f"Categorize this support ticket: {TICKET}" The weak prompt names no categories, no output format, and no tie-breaking rule, so the model invents all three, differently on every run. That's the failure you're about to fix. 3. Zero-shot: state the task completely Zero-shot means no examples, only instructions. It works when the instructions leave nothing to guess: allowed labels, a tie-breaking rule for the ambiguous case, and the exact output shape. The