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

# Best Practices

> Quick reference guide for effective prompt engineering

# Best Practices

<Info>
  Essential guidelines for crafting effective prompts across all scenarios
</Info>

## General Prompting Principles

### 1. Be Clear and Specific

<CardGroup cols={2}>
  <Card title="❌ Vague" icon="xmark">
    "Write something about AI"
  </Card>

  <Card title="✅ Specific" icon="check">
    "Write a 200-word explanation of how transformers work in AI, suitable for beginners"
  </Card>
</CardGroup>

**Guidelines:**

* Define the exact task
* Specify output format and length
* Clarify the target audience
* Include relevant constraints

***

### 2. Provide Context

<Tabs>
  <Tab title="Without Context">
    ```
    How should I respond?
    ```

    ❌ Model doesn't know what "respond" refers to
  </Tab>

  <Tab title="With Context">
    ```
    Context: A customer emailed asking about our return policy.

    How should I respond?
    ```

    ✅ Model understands the situation
  </Tab>
</Tabs>

**Guidelines:**

* Include relevant background information
* Provide examples when helpful
* Specify the domain or industry
* Clarify any ambiguous terms

***

### 3. Use Examples (Few-Shot Learning)

**When to use:**

* Task is ambiguous or complex
* Specific format is required
* Quality standards need demonstration

**How many examples:**

* Simple tasks: 1-2 examples
* Complex tasks: 3-5 examples
* Avoid: 10+ examples (diminishing returns)

***

### 4. Structure Your Prompts

**Recommended structure:**

```
[Role/Context]
[Task Description]
[Specific Instructions]
[Examples (if needed)]
[Output Format]
[Constraints]
```

***

## Task-Specific Best Practices

### Classification

<Accordion title="Do's">
  * ✅ Explicitly list all possible categories
  * ✅ Provide 2-3 examples per category
  * ✅ Specify output format: "Respond with exactly one of: A, B, C"
  * ✅ Handle edge cases: "If uncertain, respond with 'Unclear'"
</Accordion>

<Accordion title="Don'ts">
  * ❌ Use vague categories like "good" or "bad"
  * ❌ Assume the model knows your classification scheme
  * ❌ Forget to handle ambiguous cases
  * ❌ Use too many categories (>10 without hierarchy)
</Accordion>

***

### Information Extraction

<Accordion title="Do's">
  * ✅ Specify exact fields to extract
  * ✅ Provide output format (JSON, table, list)
  * ✅ Handle missing information: "If not found, use 'N/A'"
  * ✅ Use progressive extraction for complex tasks
</Accordion>

<Accordion title="Don'ts">
  * ❌ Ask for extraction without specifying format
  * ❌ Assume the model will infer what you need
  * ❌ Forget to handle incomplete data
  * ❌ Extract too many fields at once (break into steps)
</Accordion>

***

### Content Generation

<Accordion title="Do's">
  * ✅ Specify tone, style, and audience
  * ✅ Set clear length constraints
  * ✅ Provide attribute specifications
  * ✅ Include examples of desired style
  * ✅ Request specific elements (CTA, headers, etc.)
</Accordion>

<Accordion title="Don'ts">
  * ❌ Use vague instructions like "make it good"
  * ❌ Forget to specify length
  * ❌ Assume the model knows your brand voice
  * ❌ Skip audience definition
</Accordion>

***

### Text Transformation

<Accordion title="Do's">
  * ✅ Preserve core meaning and facts
  * ✅ Specify target format/style explicitly
  * ✅ Provide before/after examples
  * ✅ Set clear transformation goals
</Accordion>

<Accordion title="Don'ts">
  * ❌ Sacrifice accuracy for style
  * ❌ Use vague transformation requests
  * ❌ Forget to verify factual consistency
  * ❌ Transform without clear purpose
</Accordion>

***

### Question Answering

<Accordion title="Do's">
  * ✅ Provide relevant context when available
  * ✅ Request step-by-step reasoning for complex questions
  * ✅ Ask for source citations
  * ✅ Instruct to admit uncertainty when appropriate
</Accordion>

<Accordion title="Don'ts">
  * ❌ Expect answers without sufficient context
  * ❌ Allow hallucination of facts
  * ❌ Skip verification for critical information
  * ❌ Forget to handle "I don't know" cases
</Accordion>

***

## Advanced Techniques Best Practices

### Chain of Thought (CoT)

**When to use:**

* Multi-step reasoning required
* Math or logic problems
* Counter-intuitive questions
* Verification needed

**Best practices:**

```
✅ Use "Let's think step-by-step"
✅ Number or label each step
✅ Show all intermediate calculations
✅ Include verification step
✅ State final answer clearly

❌ Skip steps
❌ Use for simple factual questions
❌ Forget to verify
```

***

### Problem Decomposition

**When to use:**

* Hierarchical problems
* Multi-domain challenges
* Sequential dependencies
* Overwhelming complexity

**Best practices:**

```
✅ Start with simplest sub-problem
✅ Solve sequentially
✅ Use previous solutions
✅ Verify each sub-solution
✅ Synthesize clearly

❌ Decompose unnecessarily
❌ Solve out of order
❌ Skip synthesis step
```

***

### Self-Refinement

**When to use:**

* Quality-critical outputs
* Complex creative tasks
* Technical accuracy required
* Ambiguous requirements

**Best practices:**

```
✅ Generate → Critique → Refine
✅ Be specific in critiques
✅ Iterate 2-3 times for important content
✅ Focus on concrete improvements
✅ Track what changed and why

❌ Vague critiques ("could be better")
❌ Stop at first draft
❌ Refine without clear criteria
```

***

### RAG (Retrieval-Augmented Generation)

**When to use:**

* Knowledge-intensive tasks
* Dynamic information needed
* Private/proprietary data
* Citation requirements

**Best practices:**

```
✅ Ground answers in retrieved context
✅ Cite sources explicitly
✅ Admit when information is missing
✅ Never infer beyond context
✅ Verify source reliability

❌ Allow hallucinations
❌ Skip source attribution
❌ Infer missing information
❌ Use unreliable sources
```

***

## Common Pitfalls to Avoid

### 1. Prompt Ambiguity

<Warning>
  **Problem:** "Summarize this"

  **Issues:**

  * How long should the summary be?
  * What format (paragraph, bullets)?
  * What level of detail?
  * What's the purpose?

  **Solution:** "Summarize this article in 3 bullet points, each 1-2 sentences, focusing on key findings for a technical audience."
</Warning>

***

### 2. Assuming Context

<Warning>
  **Problem:** Using pronouns or references without context

  **Bad:** "How do I fix it?"

  **Good:** "How do I fix the 'Connection Timeout' error in my Python script when connecting to the database?"
</Warning>

***

### 3. Overloading the Prompt

<Warning>
  **Problem:** Trying to do too much in one prompt

  **Bad:** "Analyze this data, create visualizations, write a report, and suggest improvements"

  **Good:** Break into steps:

  1. First, analyze the data
  2. Then, create visualizations
  3. Then, write the report
  4. Finally, suggest improvements
</Warning>

***

### 4. Ignoring Output Format

<Warning>
  **Problem:** Not specifying how you want the response

  **Bad:** "Extract the key information"

  **Good:** "Extract the key information in JSON format with fields: name, date, amount, status"
</Warning>

***

### 5. Forgetting Edge Cases

<Warning>
  **Problem:** Not handling unusual inputs

  **Bad:** "Classify as positive or negative"

  **Good:** "Classify as positive, negative, or neutral. If the text is unclear or contains mixed sentiment, respond with 'mixed'."
</Warning>

***

## Debugging Strategies

### When Outputs Are Wrong

<Steps>
  <Step title="Check Clarity">
    Is your prompt clear and unambiguous?
  </Step>

  <Step title="Add Examples">
    Provide 2-3 examples of desired output
  </Step>

  <Step title="Increase Specificity">
    Add more constraints and details
  </Step>

  <Step title="Break It Down">
    Split complex tasks into simpler steps
  </Step>

  <Step title="Use CoT">
    Request step-by-step reasoning
  </Step>
</Steps>

***

### When Outputs Are Inconsistent

<Steps>
  <Step title="Constrain Format">
    Specify exact output format
  </Step>

  <Step title="Add Structure">
    Use templates or schemas
  </Step>

  <Step title="Provide More Examples">
    Show consistent patterns
  </Step>

  <Step title="Lower Temperature">
    Reduce randomness (if you control this parameter)
  </Step>
</Steps>

***

### When Outputs Are Too Generic

<Steps>
  <Step title="Add Specificity">
    Include more details and constraints
  </Step>

  <Step title="Provide Context">
    Give relevant background information
  </Step>

  <Step title="Show Examples">
    Demonstrate the level of detail needed
  </Step>

  <Step title="Request Specific Elements">
    Ask for particular details, data, or examples
  </Step>
</Steps>

***

## Performance Optimization

### Token Efficiency

**Strategies:**

* Use concise language without sacrificing clarity
* Remove redundant instructions
* Combine related constraints
* Use abbreviations consistently (after defining them)

**Example:**

```
❌ Inefficient (150 tokens):
"Please analyze the following text and provide a detailed summary. 
The summary should be comprehensive but also concise. Make sure to 
include all the key points. The summary should be easy to understand..."

✅ Efficient (50 tokens):
"Summarize this text in 100 words, covering all key points in clear, 
accessible language."
```

***

### Prompt Reusability

**Create templates for common tasks:**

```
# Customer Support Template
Context: [CUSTOMER ISSUE]
History: [PREVIOUS INTERACTIONS]
Policy: [RELEVANT POLICIES]

Task: Draft a response that:
- Acknowledges the issue
- Provides solution
- Maintains professional tone
- Offers next steps

Response:
```

***

## Quality Checklist

Before finalizing a prompt, verify:

<Check>Clear task definition</Check>
<Check>Sufficient context provided</Check>
<Check>Output format specified</Check>
<Check>Examples included (if needed)</Check>
<Check>Edge cases handled</Check>
<Check>Constraints clearly stated</Check>
<Check>Verification method included (for critical tasks)</Check>
<Check>No ambiguous language</Check>

***

## Quick Reference Card

| Scenario            | Technique        | Key Tip                               |
| ------------------- | ---------------- | ------------------------------------- |
| Simple task         | Zero-shot        | Be clear and specific                 |
| Complex task        | Few-shot         | Provide 3-5 examples                  |
| Multi-step          | Chain of Thought | "Let's think step-by-step"            |
| Hierarchical        | Decomposition    | Start simple, build up                |
| Quality-critical    | Self-refinement  | Generate → Critique → Refine          |
| High-stakes         | Ensembling       | Multiple approaches + voting          |
| Knowledge-intensive | RAG              | Ground in sources, cite               |
| Action-required     | Tool integration | Clear tool selection + error handling |

***

## Related Resources

<CardGroup cols={2}>
  <Card title="Glossary" icon="book" href="/resources/glossary">
    Key terms and definitions
  </Card>

  <Card title="Further Reading" icon="graduation-cap" href="/resources/further-reading">
    Research papers and advanced topics
  </Card>
</CardGroup>
