> For the complete documentation index, see [llms.txt](https://craft-agent.gitbook.io/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://craft-agent.gitbook.io/home/tips-and-tricks/prompt-engineering.md).

# Prompt Engineering

Writing effective prompts is the most important skill for getting great results from AI. Here are proven techniques.

## The 5 Elements of a Great Prompt

### 1. Role

Tell the AI **who it is**.

```
You are a senior software architect with 20 years of experience.
```

### 2. Task

Tell the AI **what to do**.

```
Review the following code and provide feedback.
```

### 3. Context

Give the AI **background information**.

```
The code is part of a Node.js backend for a fintech startup.
```

### 4. Format

Tell the AI **how to respond**.

```
Format your response as:
1. Summary (2 sentences)
2. Issues found (bullet list)
3. Suggestions (numbered list)
```

### 5. Constraints

Set **boundaries and rules**.

```
Keep your response under 500 words. Focus on security issues first.
```

## Complete Example

```
You are a professional copywriter specializing in SaaS products.

Write a landing page headline and subheadline for a product that:
- Helps developers automate code reviews
- Uses AI to find bugs and suggest improvements
- Integrates with GitHub

Format:
- Headline: Maximum 10 words, powerful and action-oriented
- Subheadline: Maximum 25 words, explains the value proposition

Tone: Professional but approachable. Avoid buzzwords.
```

## Common Techniques

### Chain of Thought

Ask the AI to think step by step:

```
Think through this problem step by step before giving your final answer.
```

### Few-Shot Examples

Give examples of what you want:

```
Convert these sentences to formal tone:
Input: "Hey, can you check this out?"
Output: "Could you please review the following?"

Input: "This is broken, fix it."
Output: "There appears to be an issue that requires attention."

Input: "{{user_input}}"
Output:
```

### Output Formatting

Be explicit about format:

```
Respond in valid JSON with this structure:
{
  "summary": "...",
  "key_points": ["...", "..."],
  "sentiment": "positive" | "negative" | "neutral"
}
```

## Anti-Patterns (What NOT to Do)

| ❌ Don't                | ✅ Do Instead                                                    |
| ---------------------- | --------------------------------------------------------------- |
| "Be helpful"           | "You are a tax advisor. Answer questions about US income tax."  |
| "Write something good" | "Write a 300-word product description in a conversational tone" |
| "Summarize this"       | "Summarize in exactly 3 bullet points, each under 20 words"     |

***

> **Remember:** The more specific your prompt, the better the output. Spend time crafting your system prompts — it pays off in every run.
