[Back to Course](/en/courses/prompt-engineering) Lessons

## Crafting Effective Prompts

A well-crafted prompt is the key to getting useful results from any AI agent.

### Be Specific

Vague prompts produce vague answers. Include context, format, and constraints.

### Provide Examples

Few-shot prompting gives the agent examples of what you want before asking.

### Set the Role

Define the agent’s role: “You are a data analyst…” sets the right frame.

### Iterate

Refine your prompts based on the responses you get. Prompt engineering is iterative.

### Test Variations

Experiment with different phrasings to find what works best for your use case.

* * *

### Prompt Engineering Flow

The diagram below shows the iterative prompt engineering process:

100%

### Agent-Human Interaction Flow

The sequence below illustrates how an agent processes a user prompt:

100%

### Learning Roadmap

A state diagram showing the stages of prompt engineering mastery:

100%

* * *

### 📊 Technique Comparison

The table below compares different prompt engineering techniques:

Técnica

Descripción

Mejor para

Ejemplo

Zero-Shot

Pedir al modelo una tarea sin ejemplos previos

Preguntas simples, clasificaciones rápidas

"Clasifica este email como spam o no spam"

Few-Shot

Proporcionar 2-5 ejemplos antes de la pregunta

Tareas con formato específico, extracción estructurada

"Traduce: hola → hello, adiós → goodbye, gracias → thank you"

Chain-of-Thought

Instruir al modelo a razonar paso a paso

Problemas matemáticos, lógica, debugging

"Paso 1: extraer datos. Paso 2: aplicar fórmula..."

Role-Based

Asignar un rol o personalidad al agente

Tareas especializadas, respuestas con tono consistente

"Eres un analista senior de datos financieros"

Constrained

Limitar el formato, longitud o estilo de salida

Outputs predecibles, APIs, integraciones

"Responde solo JSON con campos {{title, summary, score}}"

### ⚠️ Common Mistakes

Avoid these frequent prompt engineering pitfalls:

Error común

Problema

Solución

Ejemplo corregido

Prompt demasiado vago

El agente no tiene contexto suficiente

Incluir formato, tono, audiencia y propósito

"Resume este texto para ejecutivos en 3 párrafos"

Instrucciones contradictorias

El agente mezcla prioridades opuestas

Separar instrucciones en orden lógico, una por línea

"1. Traduce al español. 2. Mantén el tono formal."

Falta delimitación

El agente confunde instrucciones con datos

Usar \`\`\`, """ o etiquetas <instruccion>/<datos>

"Datos: {{...}}. Ahora responde: ¿cuál es el total?"

Sobrecarga de contexto

El agente pierde detalles en prompts muy largos

Priorizar información clave al inicio del prompt

Colocar la instrucción principal en las primeras 2 líneas

Sin validación explícita

El agente alucina o inventa datos

Pedir verificaciones, fuentes o confianza estimada

"Si no estás seguro, responde 'No tengo datos suficientes'"

### 📋 Evaluation Criteria

Use this framework to measure prompt quality:

Criterio

Pregunta guía

Peso

Métrica

Precisión

¿La respuesta es factualmente correcta?

30%

Comparación con ground truth

Relevancia

¿Responde directamente a la pregunta?

25%

Análisis semántico (cosine similarity)

Completitud

¿Cubre todos los aspectos solicitados?

20%

Checklist de requisitos vs output

Consistencia

¿Es coherente internamente?

15%

Detección de contradicciones

Formato

¿Cumple el formato solicitado?

10%

Validación regex / schema

* * *

### 📈 Technique Performance

Bar chart comparing accuracy, speed, and relevance across techniques:

### 🥧 Usage Distribution

Donut chart showing the distribution of technique usage:

### 📉 Improvement Trajectory

Line chart tracking prompt quality improvement over successive iterations:
