← Blog

Best Prompt Templates for the Claude API

2026-09-23 · 5 min read · SubToAPI Team

If you're searching for "best prompt templates for Claude API," you're probably trying to solve a specific task — classify text, extract structured data, summarize documents, or build a chatbot — and want a proven starting point instead of trial and error. This article gives you copy-pasteable templates for the most common production use cases, along with the structural patterns that make Claude's responses reliable and predictable.

The short answer: the best templates are the ones that explicitly separate instructions from data, define the output format up front, and give Claude a role and constraints instead of a vague ask. Below are templates you can drop straight into your API calls, organized by task.

Structure every prompt has

Regardless of task, effective Claude prompts share four parts:

  1. Role/context — who Claude is acting as and why
  2. Task instructions — the specific action, written as imperative steps
  3. Input data — wrapped in XML-style tags so it's unambiguous
  4. Output format — the exact shape you want back

Claude responds especially well to XML tags for separating instructions from content, because it removes ambiguity about where the "task" ends and the "data" begins.

Template: text classification

You are a classification system. Classify the following support ticket
into exactly one of these categories: billing, technical, feature_request, other.

Respond with only the category name, nothing else.

<ticket>
{{ticket_text}}
</ticket>

Keep the category list short and mutually exclusive. If you need confidence scores, ask for JSON explicitly (see below) rather than parsing free text.

Template: structured data extraction

Extract the following fields from the email below and return valid JSON only,
with no explanation and no markdown formatting.

Fields: sender_name, company, requested_action, deadline (ISO 8601 or null)

<email>
{{email_body}}
</email>

For extraction tasks, always specify "null" behavior explicitly — otherwise Claude may guess or omit fields inconsistently. If you're calling this through an API pipeline, validate the JSON on your side and retry once on parse failure; that's cheaper than over-engineering the prompt.

Template: summarization with length control

Summarize the following article in exactly 3 bullet points.
Each bullet must be under 20 words. Do not include an introduction or conclusion.

<article>
{{article_text}}
</article>

Vague requests like "summarize this" produce inconsistent length. Giving a hard constraint (bullet count, word limit) is what actually controls output length — Claude follows explicit numeric constraints far more reliably than qualitative ones like "briefly."

Template: document Q&A (RAG)

You are answering questions using only the provided context. If the answer
is not in the context, say "I don't have enough information to answer that."

<context>
{{retrieved_chunks}}
</context>

<question>
{{user_question}}
</question>

This is the single highest-leverage template for reducing hallucination in retrieval-augmented apps. The explicit fallback instruction matters more than model choice — without it, models tend to fill gaps with plausible-sounding guesses.

Template: code review

Review the following code diff for bugs, security issues, and readability problems.
For each issue found, respond in this format:
- Line: <line number or range>
- Severity: <low|medium|high>
- Issue: <one sentence>
- Suggested fix: <one sentence>

If no issues are found, respond with "No issues found."

<diff>
{{code_diff}}
</diff>

Structured per-issue formatting makes this parseable for CI pipelines, not just human review.

Template: system prompt for a support chatbot

You are a support assistant for {{product_name}}. Answer only questions
related to the product. If asked about anything unrelated, politely redirect
the user back to product support topics.

Tone: friendly, concise, no jargon.
Never invent pricing, features, or policies you are not given below.

<product_facts>
{{knowledge_base}}
</product_facts>

This pattern — role, scope boundary, tone, and grounding — is the backbone of nearly every production chatbot system prompt. The "never invent" line is doing more work than people expect; it's a cheap and effective guardrail against confident wrong answers.

Using these templates against the API

Once you have a template, the actual API call is the easy part. Here's the extraction template above sent through SubToAPI's /v1/messages endpoint, which mirrors Claude's message format so these prompts work without modification:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 500,
    "messages": [
      {
        "role": "user",
        "content": "Extract fields as JSON only.\n\n<email>Hi, this is Maria from Northline Logistics, need the invoice resent by Friday.</email>"
      }
    ]
  }'

If you're building a pipeline that calls these templates repeatedly across a team — one person iterating on the extraction prompt, another on the chatbot system prompt — a shared API key with usage visibility is worth setting up early. SubToAPI turns your existing Claude access into an HTTPS API with per-key usage metadata, so you can see which prompt template is burning the most tokens without adding a separate observability tool. See the quickstart to get a key running in a few minutes, or check the messages docs for the full request schema.

Iterating on templates without breaking production

A few practical rules once a template is live:

None of these templates need a specific SDK — they're plain text sent as message content, so they work identically whether you're calling Claude directly or through a proxy like SubToAPI. The templates above cover roughly 80% of what most teams build: classification, extraction, summarization, grounded Q&A, review, and chat. Start from these, adjust the constraints to your data, and resist the urge to add instructions that don't change behavior — every extra sentence in a system prompt is tokens you pay for on every single call.

FAQ

Do prompt templates need to change between Claude models? Usually not structurally — the role/task/data/format pattern works across model versions. What changes is how much instruction detail you need; larger models generally need fewer examples to follow format constraints correctly.

Should I use XML tags or JSON to wrap input data in prompts? XML-style tags (<context>...</context>) are the more reliable convention for separating instructions from data in Claude prompts. Reserve JSON for the output format you're requesting, not the input wrapper.

How do I stop Claude from adding extra commentary around JSON output? State explicitly "return valid JSON only, no explanation, no markdown code fences" in the instructions, and parse defensively on your side — strip code fences before JSON.parse as a safety net.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →