Logo for AiToolGo

Claude Prompt Engineering Best Practices: A Complete Guide to Prompting Modern Claude Models

In-depth discussion
Technical
 0
 0
 1
Guía oficial de Anthropic sobre técnicas de ingeniería de prompts para los modelos Claude actuales. Cubre principios generales (claridad, ejemplos, contexto, roles), estructuración con etiquetas XML, prompting de contexto largo, control de formato y salida, migración desde respuestas prellenadas y uso de herramientas, con orientación específica por modelo (Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5, entre otros).
  • main points
  • unique insights
  • practical applications
  • key topics
  • key insights
  • learning outcomes
  • • main points

    • 1
      Organización clara en tres niveles: orientación específica por modelo, técnicas generales y consideraciones de migración
    • 2
      Ejemplos concretos con código y comparaciones 'menos efectivo / más efectivo' que facilitan la aplicación inmediata
    • 3
      Cobertura práctica de problemas reales como control de formato, activación de herramientas y prompting de contexto largo
  • • unique insights

    • 1
      Recomienda colocar los documentos largos al principio del prompt y la consulta al final, con mejoras reportadas de hasta un 30% en pruebas
    • 2
      Advierte que los modelos más recientes responden más a la indicación del sistema, por lo que el lenguaje agresivo (p. ej. 'CRÍTICO') puede provocar sobreactivación de herramientas
  • • practical applications

    • Proporciona un marco directamente aplicable para mejorar prompts en producción: plantillas de indicaciones del sistema para acción proactiva o conservadora, estructuras XML para documentos múltiples, y estrategias de migración para eliminar respuestas prellenadas que ya no son compatibles en modelos recientes.
  • • key topics

    • 1
      Principios de claridad, contexto y uso de ejemplos (few-shot/multishot) en prompting
    • 2
      Estructuración de prompts con etiquetas XML y prompting de contexto largo con citas
    • 3
      Control del formato de salida, uso de herramientas y migración desde respuestas prellenadas
  • • key insights

    • 1
      Orientación específica por modelo que indica exactamente qué cambiar según la versión de Claude utilizada
    • 2
      Plantillas listas para copiar (indicaciones del sistema para acción proactiva/conservadora, control de Markdown, identidad del modelo)
    • 3
      Guía de migración práctica para equipos que actualizan prompts de generaciones anteriores
  • • learning outcomes

    • 1
      Aplicar técnicas de prompting claro, con ejemplos few-shot y estructuración mediante etiquetas XML en tareas reales
    • 2
      Diseñar indicaciones del sistema que controlen el nivel de acción proactiva o conservadora del modelo y el formato de salida
    • 3
      Migrar prompts de generaciones anteriores de Claude, sustituyendo respuestas prellenadas y ajustando el lenguaje de activación de herramientas
examples
tutorials
code samples
visuals
fundamentals
advanced content
practical tips
best practices

“ Introduction: Why Prompting Still Matters

Prompt engineering remains one of the most effective ways to get reliable, high-quality results from large language models. The latest generation of Claude models follows instructions with considerable precision, which means that the quality of your prompt directly shapes the quality of the output. This guide consolidates the official best practices for prompting current Claude models, including the Claude Fable, Mythos, Opus, Sonnet, and Haiku families. Treat Claude as a brilliant but newly hired colleague who lacks your context: the more clearly you explain the task, the standards, and the desired output, the better the result will be.

“ Model-Specific Guidance for the Latest Claude Models

Each Claude model family has its own prompting guide because behavior differs across models. Before applying general techniques, read the guide for your specific model. Differences include effort levels, verbosity, tool-use activation, literal instruction following, and how models handle long agentic runs. For example, Claude Opus 5 produces longer visible responses by default and does not reliably become shorter when effort is reduced, so explicit requests for concision are needed. Claude Fable 5.1 writes fewer progress updates between tool calls, so you should ask for progress text explicitly. Because capabilities and defaults shift between versions, validate any technique against your own evaluations before adopting it on a different model.

“ Core Principles: Clarity, Context, and Motivation

Claude responds best to clear, explicit instructions. Specify the output you want, including format and constraints. If you want behavior that goes beyond the default, ask for it explicitly rather than hoping the model infers it from a vague prompt. A useful test is to show your prompt to a colleague with minimal context on the task; if they would be confused, Claude likely will be too. Providing the motivation behind an instruction also helps. For instance, explaining that a response will be read aloud by a text-to-speech engine is more effective than a bare rule like 'never use ellipses,' because Claude can generalize from the explanation to related cases.

“ Using Examples Effectively

Examples are one of the most reliable ways to steer output format, tone, and structure. A few well-crafted examples, a technique often called few-shot or multishot prompting, substantially improve accuracy and consistency. Make examples relevant to your real use case, diverse enough to cover edge cases without letting unintended patterns creep in, and structured by wrapping them in tags such as <example> or <examples>, so Claude can distinguish them from instructions. Three to five examples typically yield the best results. You can also ask Claude to evaluate your examples for relevance and diversity, or to generate additional examples from your initial set.

“ Structuring Prompts with XML Tags

XML tags help Claude parse complex prompts unambiguously, especially when a prompt mixes instructions, background context, examples, and variable inputs. Wrapping each content type in its own descriptive tag, such as <instructions>, <context>, or <input>, reduces misinterpretation. Use consistent, descriptive tag names across prompts. Nest tags when content has a natural hierarchy, for instance placing individual <document index='n'> elements inside a <documents> wrapper.

“ Giving Claude a Role and Identity

Setting a role in the system prompt focuses Claude's behavior and tone for your use case. Even a single sentence makes a difference, for example: 'You are a helpful coding assistant specializing in Python.' The official guidance also covers self-identity: if your application needs Claude to identify itself correctly or to use specific model strings, state the model name and its exact API identifier in the system prompt so that it can answer accurately and select the correct model when calling other LLMs.

“ Prompting for Long Context Inputs

When working with large documents or data-rich inputs of more than roughly 20,000 tokens, structure the prompt carefully. Place long documents and inputs near the top of the prompt, above your query, instructions, and examples; this improves performance across models, and queries placed at the end can improve response quality substantially in complex multi-document tasks. Wrap each document in <document> tags with <document_content> and <source> subtags for clarity. For document-heavy tasks, ask Claude to first quote the relevant passages before performing its analysis. This grounds the response in the source material and helps Claude focus on relevant content while ignoring the rest.

“ Controlling Output Style, Verbosity, and Formatting

Recent Claude models communicate more concisely and naturally than earlier versions. They give fact-based progress reports and may skip lengthy verbal summaries after tool calls. If you want more visibility into the work performed, explicitly ask for a brief summary after completing tool-based tasks. Formatting can be steered effectively by telling Claude what to do rather than what to avoid; for example, ask for responses composed of flowing prose paragraphs rather than saying 'do not use markdown.' You can also use XML format indicators, and matching your prompt's own style to the desired output helps, since markdown-heavy prompts tend to yield markdown-heavy answers. Recent models default to LaTeX for mathematical expressions; if you prefer plain text, explicitly instruct Claude to avoid LaTeX and to write math with standard characters. Models can also create presentations and visual documents with strong instruction following, typically producing usable output on the first attempt when given a clear specification of topic, design expectations, and any animations.

“ Migrating Away from Prefilled Responses

Starting with Claude 4.6 and Claude Mythos Preview, prefilling the final assistant turn, that is, supplying a partial assistant message for Claude to continue, is no longer supported and returns a 400 error. Prefilling earlier assistant turns in a conversation is still allowed, and older models still accept prefills. Because model intelligence and instruction following have improved, most prefill use cases can be handled with other techniques. Common scenarios include controlling output format, eliminating preambles, avoiding incorrect refusals, continuing interrupted outputs, and maintaining role consistency. Migrate each by moving the requirement into the system prompt or user message, using explicit format instructions, or restructuring the conversation so the model generates the desired opening naturally.

“ Tool Use: Getting Claude to Act, Not Just Suggest

Recent Claude models follow instructions precisely and benefit from explicit direction about when to use tools. A request such as 'Can you suggest some changes?' may produce suggestions rather than implemented edits, so use directive phrasing like 'Change this function to improve its performance' when you want action. To make Claude proactive by default, add an instruction to implement changes rather than only suggesting them, inferring the most useful likely action and using tools to discover missing details. To make it more conservative, instruct it not to modify files or take action unless clearly asked, and to default to research and recommendations when intent is ambiguous. Be aware that recent Opus models respond more strongly to system prompts than predecessors, so aggressive language such as 'CRITICAL: you MUST use this tool' may now cause overtriggering; moderate it to normal phrasing like 'Use this tool when...'. Recent models also execute independent tool calls in parallel, reading multiple files at once and running searches speculatively, which speeds up agentic workflows.

“ Conclusion and Next Steps

Effective prompting for current Claude models rests on clarity, explicit direction, relevant examples, structured inputs, and attention to each model's particular behavior. Start by reading the guide for your specific model, apply the general principles, and validate every change against your own evaluations. As capabilities evolve, revisit your prompts, particularly when migrating from older generations, since techniques that once compensated for weaker instruction following may now cause overtriggering, verbosity, or unwanted formatting.

 Original link: https://platform.claude.com/docs/es/build-with-claude/prompt-engineering/claude-prompting-best-practices

Comment(0)

user's avatar

      Related Tools