AI Integration

Prompt Engineering

Best practices for crafting effective AI prompts and system instructions.

Prompt engineering is the art of crafting instructions that guide AI models to produce the outputs you want. Good prompts can dramatically improve the quality, consistency, and usefulness of AI responses in your application.

System Prompts

System prompts are instructions that shape the AI's behavior for every conversation. They're invisible to users but define your AI assistant's personality, capabilities, and limitations.

When to Use System Prompts

Define Personality

Give your AI a consistent voice, tone, and character that matches your brand.

Set Boundaries

Restrict the AI from discussing certain topics or performing unwanted actions.

Provide Context

Give the AI knowledge about your product, company, or domain.

Format Responses

Specify how the AI should structure its answers (length, format, style).

Adding System Prompts to Your Chat

To add a system prompt, modify the messages array before sending to the API. Add a message with role: 'system' at the beginning of the conversation:

const systemPrompt = `You are a helpful customer support assistant for Acme Inc.
You help users with product questions, troubleshooting, and account issues.
Always be friendly, concise, and professional.
If you don't know something, say so honestly.`

// Prepend to messages before sending
const messagesWithSystem = [
  { role: 'system', content: systemPrompt },
  ...userMessages
]

Prompt Best Practices

Be Specific

Vague prompts lead to vague answers. Tell the AI exactly what you want.

Write about our product.

Provide Examples

Show the AI what good output looks like. This technique is called "few-shot prompting."

Format customer feedback as follows:

Example:
Input: "Love the app but wish it had dark mode"
Output: { "sentiment": "positive", "feature_request": "dark mode", "category": "ui" }

Now format this feedback:
Input: "The search is too slow, takes forever to find anything"

Use Role Playing

Assign the AI a specific role to get more focused responses.

You are an expert TypeScript developer with 10 years of experience.
Review the following code for potential bugs, performance issues, 
and TypeScript best practices.

Break Down Complex Tasks

Instead of one massive prompt, break complex tasks into steps.

Step 1: Gather Information

Ask the AI to list what it needs to know.

Step 2: Process Data

Have the AI analyze or transform the information.

Step 3: Generate Output

Request the final formatted result.

Set Constraints

Tell the AI what NOT to do, not just what to do.

Constraints:
- Do not make up information. If unsure, say "I don't know."
- Do not discuss competitors or make comparisons.
- Keep responses under 200 words unless asked for more detail.
- Never share pricing information—direct users to the pricing page.

Prompt Templates

Here are some templates you can adapt for common use cases:

Customer Support Bot

You are a customer support assistant for [Company Name].

Your role:
- Answer questions about our products and services
- Help troubleshoot common issues
- Guide users through our features

Your personality:
- Friendly and patient
- Professional but approachable
- Concise—respect the user's time

Rules:
- If you don't know something, say so and offer to connect them with a human
- Never share internal information or policies not meant for customers
- For billing issues, direct users to billing@company.com

Code Assistant

You are a senior software developer helping with [Language/Framework].

When reviewing code:
- Identify bugs and potential issues
- Suggest performance improvements
- Follow [language] best practices and conventions
- Explain your reasoning

When writing code:
- Write clean, readable code with comments
- Include error handling
- Follow the existing code style in the project

Content Generator

You are a content writer for [Industry/Niche].

Writing style:
- [Formal/Casual/Professional]
- Target audience: [Description]
- Tone: [Friendly/Authoritative/Educational]

Requirements:
- SEO-friendly with natural keyword usage
- Include actionable takeaways
- Use short paragraphs and bullet points for readability

Model-Specific Tips

Different models have different strengths. Optimize your prompts accordingly:

ModelBest ForTips
GPT-4oComplex reasoning, codingCan handle longer contexts, good at following complex instructions
ClaudeLong documents, analysisExcellent at nuanced tasks, tends to be more cautious
GeminiMultimodal, factual queriesGood at structured outputs, strong with current information

Testing Your Prompts

Always test prompts with edge cases. What happens if a user asks something unexpected or tries to "jailbreak" your AI?

Testing Checklist

  • Does it handle typical user queries correctly?
  • Does it gracefully handle off-topic questions?
  • Does it stay within defined boundaries?
  • Is the response format consistent?
  • Does it work across different models?

Token Optimization

System prompts consume tokens on every request. Keep them concise:

  • Remove redundant instructions
  • Use bullet points instead of paragraphs
  • Test if shorter prompts achieve the same results
  • Consider dynamic prompts that change based on context

Further Reading