Production-Grade Prompting with the Anthropic API

Search for a command to run...

No comments yet. Be the first to comment.
Claude is incredibly good at reasoning. But reasoning is only as useful as the context available to it. Your architecture might be in GitHub. Your notes might be in Obsidian. Your decisions might be b

Mind maps are an excellent addition to an MCP ecosystem when they help users understand relationships between data, tools, and reasoning. They should complement—not replace—traditional dashboards, tab
Most AI agents today depend heavily on cloud APIs. They're fast, but every request costs money, depends on an internet connection, and sends your data to external providers. Over the weekend, I experi
How I use Fable 5 to research, build, and maintain custom Claude Code plugins, marketplaces, agents, and skills—creating reusable AI tooling that works across every project. 01 · The problem with copy

The way people search is changing. Is your site ready? For the past two decades, SEO (Search Engine Optimization) was the undisputed king of web visibility. Rank on Google's first page and you win tr
Prompting in Anthropic (Claude) is not just about writing good instructions.
In production systems, prompts behave more like specifications than conversations.
This article explains how prompting actually works in Anthropic, how to design reliable and compliant prompts, and how to use JavaScript to build real systems—ending with a production-grade sentiment analysis prompt.
Anthropic uses a message-based API.
Each request contains the entire conversation state.
Claude does not remember anything between API calls.
You → send full conversation
Claude → continues from that context
Every request must include:
Who the assistant is
What rules apply
What the user just said
Any images or documents
Anthropic uses three roles:
| Role | Purpose |
system | Hard rules, behavior, constraints |
user | Input data or tasks |
assistant | Previous model replies (conversation priming) |
messages: [
{ role: "user", content: "Hello! Only speak Spanish." },
{ role: "assistant", content: "Hola!" },
{ role: "user", content: "How are you?" }
]
Claude will answer in Spanish because:
Conversation history establishes the rule
Claude prioritizes consistency
Put non-negotiable rules in
system, not in conversation history.
| Instruction Type | Reliability |
| System | Strong, persistent |
| User | Soft, overrideable |
| Assistant | Priming only |
system: "You must respond only in Spanish."
This survives:
Long conversations
Truncated history
User attempts to override
Temperature controls how predictable Claude’s word choices are.
It does not control intelligence.
| Temperature | Behavior | Use case |
| 0.0–0.2 | Deterministic | JSON, analytics |
| 0.3–0.5 | Controlled | Summaries |
| 0.6–0.8 | Creative | Writing |
| 0.9+ | Unstable | Rarely useful |
temperature: 0.0
Use this when:
Output must be parsed
Compliance matters
Decisions depend on correctness
stop_sequences tells Claude when to stop generating.
stop_sequences: ["\nUser:"]
Claude stops immediately when it reaches that string.
Prevent role leakage
End JSON cleanly
Stop agent loops
Stop sequences are guards, not fixes for bad prompts.
Streaming lets Claude send text incrementally.
with client.messages.stream(...) as stream:
for text in stream.text_stream:
print(text)
Faster perceived response
Better UX
Long outputs
JSON APIs
Tool calls
Strict schema validation
let buffer = "";
for (const chunk of stream.text_stream) {
buffer += chunk;
process.stdout.write(chunk);
}
// buffer now contains the full response
Anthropic allows image + text together.
{
role: "user",
content: [
{ type: "image", source: {...} },
{ type: "text", text: "Count the containers." }
]
}
content must be an array
Image first, instruction second
Images only in user role
cache_controlAnthropic optimizes performance by caching repeated prompt prefixes.
This is good for:
System prompts
Templates
Policies
But dangerous for:
User data
Transcripts
Images
PII
cache_control: { type: "ephemeral" }"cache_control": { "type": "ephemeral" }
This means:
Use this content once. Do not cache. Do not reuse. Do not persist.
| Data | Ephemeral |
| User input | ✅ |
| Call transcripts | ✅ |
| Images | ✅ |
| Customer feedback | ✅ |
Prevents data reuse
Improves compliance posture
Reduces audit risk
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY
});
const response = await client.messages.create({
model: "claude-3-5-sonnet-20240620",
max_tokens: 200,
temperature: 0.0,
system: "You are a deterministic analysis engine.",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "The service was slow and frustrating.",
cache_control: { type: "ephemeral" }
}
]
}
]
});
console.log(response.content[0].text);
A production prompt has:
Clear role definition
Explicit constraints
Defined output format
Fail-closed behavior
Low temperature
No exposed reasoning
Safe handling of sensitive data
Good prompts are specifications, not conversations.
This prompt follows all best practices discussed above.
Analyze the sentiment of the following customer message.
Rules:
- Classify sentiment as POSITIVE, NEGATIVE, or NEUTRAL
- Do not include personal data
- Do not infer intent beyond the text
- Limit text fields to 100 characters
Output:
Return ONLY valid JSON.
No explanations.
Schema:
{
"sentiment": "POSITIVE | NEGATIVE | NEUTRAL",
"confidence": 0.0-1.0,
"summary": "string"
}
If sentiment cannot be determined, return:
{
"sentiment": "NEUTRAL",
"confidence": 0.0,
"summary": "Insufficient data"
}
const response = await client.messages.create({
model: "claude-3-5-sonnet-20240620",
max_tokens: 150,
temperature: 0.0,
system: "You are a strict sentiment classification engine.",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "Support was slow and unhelpful.",
cache_control: { type: "ephemeral" }
}
]
}
]
});
console.log(response.content[0].text);
Anthropic prompting works best when you treat prompts like contracts: explicit, constrained, deterministic, and safe.