Prompt Engineering: Guía completa para Claude

Introduction: Why Prompt Engineering Matters

Prompt engineering is the practice of crafting inputs to AI language models to reliably get the outputs you want. It's the difference between an AI that frustrates you and one that functions as a genuine force multiplier for your work.

This guide is grounded in Anthropic's official documentation for Claude. The techniques here apply whether you're using Claude.ai directly or building via the API. Based on Anthropic's official documentation · Claude 4.6 Edition. Full docs: platform.claude.com/docs

Golden Rule: Show your prompt to a colleague with minimal context and ask them to follow it. If they'd be confused, Claude will be too.

BEGINNER

Chapter 1: Basic Prompt Structure

Every interaction with Claude has two core layers: System Prompt — sets context, persona, and rules; persistent across the whole conversation. User Message — the actual task or question for this turn. Flow: System Prompt → Who Claude is, rules, format preferences. User Message → The specific task. Assistant Turn → Claude's response.

System prompts answer

  • What role is Claude playing?
  • What are the rules and constraints?
  • What format should output take?
  • Who is the audience?

Key facts

  • Claude has no memory between separate conversations — only within one. Use the system prompt for persistent context.
  • Claude Sonnet 4.6 has a 200,000-token context window (~150,000 words). Beyond this, earlier parts fall out.
  • For long documents, put them near the top; put questions and instructions at the end — Anthropic's testing shows up to 30% quality improvement on complex inputs.

Chapter 2: Being Clear and Direct

This is the single most important skill. Think of Claude as a brilliant but new employee who lacks context. Specify output explicitly (length, format, focus, audience). Use positive instructions (what TO do), not negative. Provide context and motivation (explain WHY). Use sequential steps for complex tasks. Apply the Colleague Test before sending.

Chapter 3: Assigning Roles

Giving Claude a specific role changes vocabulary, expertise level, depth of analysis. Use strong roles (specific domain and audience), not weak ("helpful assistant"). Types: professional (lawyer, doctor), functional (editor, Devil's advocate), brand/character (Sofia for BateauBillet). Put role in system prompt; be specific; add user/audience context; include personality traits. Don't ask Claude to play roles that conflict with its values.

INTERMEDIATE

Chapter 4: Separating Data from Instructions

Use XML tags so Claude can distinguish instructions from data. Standard tags: <instructions>, <context>, <document>, <example>/<examples>, <input>, <output_format>, <constraints>. For multiple documents use nested <documents>/<document>. Long-context best practices: documents first, instructions and questions last; ask Claude to quote relevant passages before answering.

Chapter 5: Formatting Output & Speaking for Claude

Specify format explicitly: direct instruction, XML tags, or a template. Tell Claude what TO do; match prompt style to desired output. Control verbosity (comprehensive vs. extremely concise). Eliminate preambles: "Skip any introduction," "Begin with the JSON object." Common formats: JSON only, markdown table, structured sections (SUMMARY, KEY FINDINGS, RECOMMENDATION, NEXT STEPS).

Chapter 6: Precognition (Thinking Step by Step)

Ask Claude to reason before answering for math, logic, multi-step analysis, ambiguous tasks, auditing reasoning, complex debugging. Skip for simple facts, creative writing, speed-critical tasks. Patterns: simple ("Think step by step"); structured (list facts, assumptions, logic, conclusion); tagged (<thinking> and <answer>). Claude 4.6: adaptive thinking API (effort: low/medium/high/max). Add self-verification. Alternative to "think": "consider," "evaluate," "reason through."

Chapter 7: Using Examples

Few-shot prompting is one of the most reliable accuracy boosters. Wrap examples in <examples>/<example> with <input> and <output>; end with actual <input>. Good examples: relevant, diverse (edge cases), consistent format, 3–5 examples. Avoid: only easy examples, same-looking inputs, inconsistent format, too few examples, missing real task. For complex tasks include <thinking> in examples. Meta-tip: Ask Claude to evaluate your examples.

ADVANCED

Chapter 8: Avoiding Hallucinations

Ground answers in provided text; explicitly permit "I don't know"; require citations; verify before finishing; for numbers show calculation; use structured output; for agents require file reading before claims. Use <investigate_before_answering> for agentic systems. Calibrated uncertainty: HIGH/MEDIUM/LOW/UNKNOWN. Self-verification prompt: re-read question, check answer addresses it, confirm claims supported, correct assumptions.

Chapter 9: Building Complex Prompts (Industry Use Cases)

Chatbot: <role>, <personality>, <knowledge_base>, <response_format>, <edge_cases> — persona, boundaries, tone, graceful failure. Legal: ground in documents only, "I cannot determine this," disclaimers, clause citations; <role> analyst not advisor, <constraints>, <output_format> FINDING/SOURCE/QUOTE/NOTES. Financial: analyst for own data, no investment advice, flag >20% deviations, structured report, mandatory disclaimer. Coding: minimal changes, no unsolicited features, explain changes, ask if ambiguous, <principles>, <constraints>, <output_format> with approach/code/changes/test.

Congratulations & Next Steps

  • Practice: Build a production prompt for a real workflow — role → instructions → XML → examples → anti-hallucination → format.
  • Iterate: Test edge cases, refine, keep a prompt library.
  • Evaluate: Build evals (test inputs + expected outputs) for production.
  • Resources: platform.claude.com/docs

Appendix: Beyond Standard Prompting

A.1 Chaining Prompts

Break complex tasks into sequential API calls; output of one → input of next. When: task too complex for one prompt, need to inspect/validate intermediates, different roles per step, or generate → review → refine. Self-correction: Generate draft → Critique against criteria → Refine. Claude 4.6 handles much multi-step reasoning internally; chaining still valuable for inspectable pipelines.

A.2 Tool Use

Claude calls external systems (APIs, DBs, search, custom functions). Flow: define tools (name, description, schema) → Claude decides when to call → formats call → your code runs → Claude synthesizes. Describe when to use the tool; include examples; specify limitations; avoid "ALWAYS" — use "Use this tool when...". Parallel tool calling: Claude 4.6 can call multiple tools at once when independent; <use_parallel_tool_calls>.

A.3 Search & Retrieval (RAG)

RAG: user asks → search knowledge base → inject top results → Claude answers from docs. Prompt: answer ONLY from <search_results>; cite source per claim; if insufficient say "Based on available documentation..."; if unanswerable "I don't have information about that." Put user question after the documents — up to 30% accuracy gain on complex multi-document queries.

Quick Reference

  • Prompt Structure — System = persistent context; user message = specific task
  • Be Clear & Direct — Specify format, length, tone, audience
  • Role Assignment — Persona in system prompt with expertise and context
  • XML Tags — <instructions>, <context>, <document> to separate content
  • Output Format — Tell Claude what TO do; match style to output
  • Step-by-Step — Reason before answering for complex tasks
  • Examples — 3–5 diverse in <example>; include edge cases
  • Anti-Hallucination — Ground in docs; citations; allow "I don't know"
  • Prompt Chaining — Generate → Review → Refine for high-stakes
  • Tool Use — "When to use" descriptions; parallel calling
  • RAG — Docs BEFORE query; source citations
  • Adaptive Thinking — effort (low/medium/high/max)

Full Anthropic documentation: platform.claude.com/docs

Preguntas frecuentes

What is the Golden Rule of prompt engineering?
Show your prompt to a colleague with minimal context and ask them to follow it. If they'd be confused, Claude will be too. Add the missing context and specificity.
Where should I put long documents in my prompt?
Put long documents near the top of your prompt and put your questions and instructions at the end. Anthropic's testing shows this can improve quality by up to 30% on complex inputs.
How do I reduce hallucinations?
Ground responses in provided documents only; explicitly allow "I don't know"; require citations or quotes; ask Claude to verify before finishing; use structured output (e.g. JSON); for agents require reading files before making claims.
When should I use prompt chaining vs. one prompt?
Use chaining when the task is too complex for one prompt, you need to inspect intermediate results, different steps need different roles, or you want a generate → review → refine pipeline. Claude 4.6 handles much multi-step reasoning internally; chaining is for inspectable pipelines.