agentleFS
VersoXBTVersoXBT/claude-initial-setup/skills/claude-api/prompt-engineering/SKILL.md

prompt-engineering

Skill4 starsChanged 9 months agoMITView on GitHub

Prompt engineering patterns for Claude including system prompts, few-shot examples, chain-of-thought, structured output, templates, and prefilling. Use when the user is writing prompts, designing system instructions, extracting structured data, building prompt templates, or optimizing Claude responses for quality and consistency.

63 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use security-checklist, llm-evaluation and 7 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • atuljha23Skill

    security-checklist

    OWASP-style quick reference — authn/authz, injection, secrets, sessions, crypto, dependencies. Use during code review and before committing security-sensitive changes.

    Also in 3 projects that use this

  • stefan-jansenSkill

    llm-evaluation

    LLM evaluation and testing patterns including prompt testing, hallucination detection, benchmark creation, and quality metrics. Use when testing LLM applications, validating prompt quality, implementing systematic evaluation, or measuring LLM performance.

    Also in 3 projects that use this

  • rohitg00Skill

    data-engineering

    Data engineering patterns for ETL pipelines, data warehousing, Apache Spark, and data quality validation

    Also in 3 projects that use this

  • mrgoonieSkill

    context-engineering

    Master context engineering for AI agent systems. Use when designing agent architectures, debugging context failures, optimizing token usage, implementing memory systems, building multi-agent coordination, evaluating agent performance, or developing LLM-powered pipelines. Covers context fundamentals, degradation patterns, optimization techniques (compaction, masking, caching), compression strategies, memory architectures, multi-agent patterns, LLM-as-Judge evaluation, tool design, and project development.

    Also in 7 projects that use this

  • CloudAI-XSkill

    database-design

    Designs database schemas, indexing strategies, query optimization, and migration patterns for SQL and NoSQL databases. Use when designing tables, optimizing queries, fixing N+1 problems, planning migrations, or when asked about database performance, normalization, ORMs, or data modeling.

    Also in 4 projects that use this

  • dylantarreSkill

    performance-optimization

    Use when animation runs slow, janky, or causes frame drops

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 56 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use the messages array with alternating user/assistant turns.

    line 45
  2. Distinctive:

    Ask Claude to reason step-by-step before giving a final answer.

    line 65
  3. Distinctive:

    Not using XML tags to delimit sections in complex prompts

    line 192
  4. Distinctive:

    Put the most important instructions at the beginning and end of the system prompt.

    line 210
  5. Very specific:

    Use XML tags (<context>, <instructions>, <examples>) for clear prompt structure.

    line 211

“Common” is measured: kept by at least 6 in 10 of the 56 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Prompt Engineering

Patterns and techniques for crafting effective Claude prompts. Covers system prompts, few-shot learning, chain-of-thought reasoning, structured output, and prefilling.

When to Use

  • User is writing or optimizing prompts for Claude
  • User needs structured JSON output from Claude
  • User is designing system prompts or instructions
  • User wants chain-of-thought reasoning or few-shot examples
  • User is building prompt templates for reuse

Core Patterns

System Prompts

System prompts set Claude's persona, constraints, and output format. Place stable instructions here; they are cached separately and can use prompt caching.

message = client.messages.create(
    model="claude-sonnet-4-6-20250514",
    max_tokens=1024,
    system="""You are a senior code reviewer. Follow these rules:
1. Focus on bugs, security issues, and performance problems.
2. Rate severity as CRITICAL, HIGH, MEDIUM, or LOW.
3. Provide a fix for each issue found.
4. If the code is clean, say "No issues found." and nothing else.""",
    messages=[{"role": "user", "content": f"Review this code:\n```\n{code}\n```"}]
)

Few-Shot Examples

Provide 2-4 input/output examples to demonstrate the exact format and reasoning you expect. Use the messages array with alternating user/assistant turns.

messages = [
    {"role": "user", "content": "Classify: 'My order never arrived and nobody responds to emails'"},
    {"role": "assistant", "content": '{"category": "shipping", "sentiment": "negative", "priority": "high"}'},
    {"role": "user", "content": "Classify: 'Love the new feature update, works great!'"},
    {"role": "assistant", "content": '{"category": "feedback", "sentiment": "positive", "priority": "low"}'},
    {"role": "user", "content": f"Classify: '{user_input}'"}
]

message = client.messages.create(
    model="claude-sonnet-4-6-20250514",
    max_tokens=256,
    messages=messages
)

Chain-of-Thought Reasoning

Ask Claude to reason step-by-step before giving a final answer. Use extended thinking for complex problems that benefit from deep reasoning.

# Extended thinking (built-in chain-of-thought)
message = client.messages.create(
    model="claude-sonnet-4-6-20250514",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000  # tokens allocated for reasoning
    },
    messages=[{"role": "user", "content": "Debug this function and explain the root cause:\n" + code}]
)

# Access thinking and response separately
for block in message.content:
    if block.type == "thinking":
        print("Reasoning:", block.thinking)
    elif block.type == "text":
        print("Answer:", block.text)
# Manual chain-of-thought via prompt
message = client.messages.create(
    model="claude-sonnet-4-6-20250514",
    max_tokens=2048,
    system="Think step-by-step. Show your reasoning in <reasoning> tags, then give the final answer.",
    messages=[{"role": "user", "content": "What is the time complexity of merge sort and why?"}]
)

Structured Output (JSON Mode)

Force Claude to return valid JSON by combining system instructions with prefilling.

message = client.messages.create(
    model="claude-sonnet-4-6-20250514",
    max_tokens=1024,
    system="""Extract entities from the text. Return a JSON object with this exact schema:
{
  "people": [{"name": string, "role": string}],
  "organizations": [{"name": string, "type": string}],
  "locations": [{"name": string, "context": string}]
}
Return ONLY valid JSON, no other text.""",
    messages=[
        {"role": "user", "content": f"Extract entities from: {text}"},
        {"role": "assistant", "content": "{"}  # Prefill forces JSON start
    ]
)

# Reconstruct the full JSON (prefill is not included in response)
import json
result = json.loads("{" + message.content[0].text)

Prefilling Assistant Responses

Prefill the assistant turn to control output format, language, or starting point.

# Force a specific output format
message = client.messages.create(
    model="claude-sonnet-4-6-20250514",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Translate to French: 'Hello, how are you?'"},
        {"role": "assistant", "content": "Bonjour"}  # Forces French output
    ]
)

# Force code-only output
message = client.messages.create(
    model="claude-sonnet-4-6-20250514",
    max_tokens=2048,
    messages=[
        {"role": "user", "content": "Write a Python function to calculate fibonacci numbers."},
        {"role": "assistant", "content": "```python\n"}  # Forces code block
    ]
)

Prompt Templates

Build reusable prompt templates with clear variable boundaries using XML tags.

REVIEW_TEMPLATE = """Review the following pull request diff.

<diff>
{diff}
</diff>

<context>
Repository: {repo_name}
Language: {language}
PR Description: {pr_description}
</context>

<instructions>
1. Identify bugs, security issues, and performance problems.
2. Suggest improvements with code examples.
3. Rate overall quality: APPROVE, REQUEST_CHANGES, or COMMENT.
</instructions>"""

message = client.messages.create(
    model="claude-sonnet-4-6-20250514",
    max_tokens=4096,
    messages=[{
        "role": "user",
        "content": REVIEW_TEMPLATE.format(
            diff=diff_text,
            repo_name="my-app",
            language="TypeScript",
            pr_description="Add user authentication"
        )
    }]
)

Anti-Patterns

  • Using vague instructions like "be helpful" instead of specific behavioral rules
  • Putting variable content in the system prompt (defeats prompt caching)
  • Providing more than 5 few-shot examples (diminishing returns, wastes tokens)
  • Not using XML tags to delimit sections in complex prompts
  • Asking Claude to "never" do something instead of stating what it should do
  • Using temperature=1.0 for structured output (use 0.0 for deterministic JSON)
  • Prefilling with invalid syntax that forces Claude into a broken output format

Quick Reference

TechniqueWhen to Use
System promptStable instructions, persona, output format
Few-shotClassification, formatting, style matching
Chain-of-thoughtMath, logic, debugging, multi-step reasoning
Extended thinkingComplex analysis, deep reasoning tasks
PrefillingForce output format, language, code blocks
XML tagsDelimit sections in complex prompts
JSON modeStructured data extraction, API responses

Key tips:

  • Put the most important instructions at the beginning and end of the system prompt.
  • Use XML tags (<context>, <instructions>, <examples>) for clear prompt structure.
  • Set temperature=0 for deterministic tasks, temperature=0.5-1.0 for creative tasks.
  • Prefilled content is NOT included in the response -- prepend it when parsing.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.