> ## Documentation Index
> Fetch the complete documentation index at: https://docs.endprompt.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Prompt Engineering Best Practices

> Tips for writing effective, reliable prompts

Great prompts produce consistent, high-quality results. This guide covers proven patterns for writing effective prompts in Endprompt.

## Core Principles

<CardGroup cols={2}>
  <Card title="Be Specific" icon="bullseye">
    Tell the model exactly what you want, step by step
  </Card>

  <Card title="Show, Don't Tell" icon="eye">
    Include examples of desired output
  </Card>

  <Card title="Constrain Output" icon="brackets-curly">
    Specify exact format, length, and structure
  </Card>

  <Card title="Handle Edge Cases" icon="code-branch">
    Tell the model what to do when things go wrong
  </Card>
</CardGroup>

## Prompt Structure

A well-structured prompt typically includes:

```liquid theme={null}
[1. Role/Context]
You are a [specific role] with expertise in [domain].

[2. Task Definition]
Your task is to [specific action].

[3. Detailed Instructions]
Follow these steps:
1. First, do X
2. Then, do Y
3. Finally, do Z

[4. Input Data]
Here is the data to process:
{{ inputs.data }}

[5. Output Format]
Return your response as [format] with the following structure:
{
  "field1": "description",
  "field2": "description"
}

[6. Constraints]
- Do not include [unwanted things]
- Always include [required things]
- If [edge case], then [behavior]
```

## Techniques

### Few-Shot Learning

Provide examples to show the model what you want:

```liquid theme={null}
Classify the following customer feedback as positive, negative, or neutral.

Examples:
- "Great product, fast shipping!" → positive
- "Arrived broken, very disappointed" → negative
- "It works as described" → neutral

Now classify:
{{ inputs.feedback }}
```

<Tip>
  3-5 examples is usually enough. More examples improve consistency but increase token usage.
</Tip>

### Chain of Thought

Ask the model to reason step-by-step:

```liquid theme={null}
Analyze this investment opportunity. Think through it step by step:

1. First, identify the key financial metrics
2. Then, assess the market conditions
3. Next, evaluate the risks
4. Finally, provide your recommendation

Data:
{{ inputs.investment_data }}

Show your reasoning for each step before giving your final recommendation.
```

### Role Assignment

Give the model a specific persona:

```liquid theme={null}
You are a senior software architect with 15 years of experience in distributed systems. 
You are known for giving practical, implementation-focused advice.
You always consider scalability, maintainability, and cost.

Review this system design and provide feedback:
{{ inputs.design }}
```

### Negative Instructions

Tell the model what NOT to do:

```liquid theme={null}
Summarize this article.

Do NOT:
- Include your own opinions
- Add information not in the original
- Use marketing language
- Exceed 100 words

{{ inputs.article }}
```

## JSON Output Patterns

### Explicit Structure

```liquid theme={null}
Return your response as a JSON object with exactly these fields:
{
  "sentiment": "positive" | "negative" | "neutral",
  "confidence": 0.0 to 1.0,
  "keywords": ["array", "of", "strings"],
  "summary": "one sentence summary"
}

Return ONLY the JSON object, no additional text.
```

### Error Handling in Output

```liquid theme={null}
If you cannot complete the analysis:
{
  "error": true,
  "reason": "explanation of why"
}

If successful:
{
  "error": false,
  "result": { ... }
}
```

## Common Patterns

### Classification

```liquid theme={null}
Classify the following text into exactly one category:
- Category A: [description]
- Category B: [description]
- Category C: [description]

Text: {{ inputs.text }}

Return: {"category": "selected_category", "confidence": 0.0-1.0}
```

### Extraction

```liquid theme={null}
Extract the following information from the text:
- Person names (list)
- Dates mentioned (ISO format)
- Monetary amounts (with currency)
- Action items (list)

If a field has no matches, return an empty array.

Text: {{ inputs.text }}
```

### Generation with Constraints

```liquid theme={null}
Write a {{ inputs.content_type }} about {{ inputs.topic }}.

Constraints:
- Length: {{ inputs.word_count | default: 200 }} words
- Tone: {{ inputs.tone | default: "professional" }}
- Audience: {{ inputs.audience | default: "general" }}
- Must include: {{ inputs.required_points | join: ", " }}
- Must avoid: {{ inputs.avoid_topics | join: ", " | default: "nothing specific" }}
```

### Transformation

```liquid theme={null}
Rewrite the following text to:
- Use {{ inputs.reading_level | default: "8th grade" }} reading level
- Maintain the original meaning
- Be approximately the same length

Original:
{{ inputs.text }}
```

## Temperature Guidelines

| Task             | Temperature | Why                                    |
| ---------------- | ----------- | -------------------------------------- |
| Classification   | 0.0-0.2     | Consistent categories                  |
| Data extraction  | 0.0-0.2     | Accurate parsing                       |
| Summarization    | 0.2-0.4     | Consistent structure, some flexibility |
| Rewriting        | 0.4-0.6     | Balance of faithful and fresh          |
| Creative writing | 0.7-0.9     | Variety and creativity                 |
| Brainstorming    | 0.8-1.0     | Maximum diversity                      |

## Testing Your Prompts

### Run Multiple Times

Test the same input 5-10 times to check consistency:

* With temperature 0, outputs should be nearly identical
* Higher temperatures should vary within acceptable bounds

### Test Edge Cases

Always test with:

* Empty optional fields
* Very long inputs
* Unusual characters (emoji, unicode)
* Inputs in different languages
* Adversarial inputs (attempts to break the prompt)

### Compare Models

Test with different models to find the best balance of:

* Quality
* Speed
* Cost

## Common Mistakes

<AccordionGroup>
  <Accordion title="Vague instructions" icon="question">
    ❌ "Summarize the text"
    ✅ "Write a 3-sentence summary covering the main argument, key evidence, and conclusion"
  </Accordion>

  <Accordion title="No output format" icon="brackets-curly">
    ❌ "Analyze the sentiment"
    ✅ `Return JSON: {"sentiment": "positive"|"negative"|"neutral", "score": 0-1}`
  </Accordion>

  <Accordion title="Missing edge cases" icon="code-branch">
    ❌ "Extract the email address"
    ✅ `Extract the email address. If none found, return {"email": null}`
  </Accordion>

  <Accordion title="Too many instructions" icon="list">
    ❌ 50 bullet points of instructions
    ✅ Clear, numbered steps with examples
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Use Cases" icon="lightbulb" href="/guides/use-cases">
    See real-world prompt examples
  </Card>

  <Card title="Liquid Templating" icon="code" href="/prompts/liquid-templating">
    Make prompts dynamic
  </Card>
</CardGroup>
