Careeroza
Prompt Engineering
What makes a good prompt?
- A clear role and task in the system prompt, with the audience and goal.
- All needed context, separated with tags (
<docs>,<question>). - A few diverse examples (few-shot) for format and tone.
- An explicit output format (or structured outputs), and what to do when unsure.
- Tested against an eval set, not one happy-path example.
What is the difference between zero-shot, few-shot and chain-of-thought prompting?
| Technique | What it is | When |
|---|---|---|
| Zero-shot | just the instruction | simple, common tasks |
| Few-shot | instruction + a few input/output examples | specific formats, labels, tone |
| Chain of thought | ask the model to reason step by step before answering | maths, multi-step logic |
Current Claude models think internally (adaptive thinking), so you mostly control depth with the effort setting instead of writing "think step by step".
How do you get reliable JSON out of an LLM?
Best: use the API's structured outputs, which constrain the output to your schema. With the Python SDK, client.messages.parse(..., output_format=MyPydanticModel) returns a validated object in response.parsed_output. Without that feature: describe the schema, give an example, parse with json.loads, validate with Pydantic, and retry once with the validation error in the prompt.
from pydantic import BaseModel
class Ticket(BaseModel):
intent: str
order_id: str | None
urgent: bool
resp = client.messages.parse(
model="claude-haiku-5-5", max_tokens=500,
messages=[{"role": "user", "content": "Classify: 'SE1042 not delivered, need it for a wedding tomorrow!'"}],
output_format=Ticket,
)
print(resp.parsed_output) # intent='delivery_delay' order_id='SE1042' urgent=TrueHow do you version and manage prompts in a team?
- Store prompts in git as files or constants with an ID (
support_v7), not inside random code strings. - Log the prompt version with every request.
- Every change runs the eval set in CI; regressions block the merge.
- Roll out big changes gradually (canary or A/B) and watch online metrics.