Prompt Engineering
Effective prompts are crucial for getting high-quality results from language models. This guide covers best practices and tips for prompt engineering with AI SDK Core.Basic Principles
Be Specific and Clear
Provide clear, specific instructions:Use System Messages
Set the model’s role and behavior with system messages:Provide Context
Include relevant context in your prompts:Prompts for Tools
When using tools, follow these best practices:1. Use Strong Models
Use models that excel at tool calling:2. Limit the Number of Tools
Keep tools focused and limited (5 or fewer recommended):3. Use Descriptive Names
Choose semantic, meaningful names:4. Write Detailed Descriptions
Provide comprehensive tool and parameter descriptions:5. Keep Schemas Simple
Avoid overly complex nested structures:6. Document Tool Output
When tool dependencies exist, describe output in the tool description:7. Provide Examples
Include example tool usage in prompts:Prompts for Structured Data
Use Clear Property Descriptions
Handle Dates Properly
Use string schemas with transformations for dates:Use Nullable for Optional Fields
For maximum compatibility with strict schemas:Set Temperature to 0
For deterministic structured output:Debugging Prompts
Inspect Warnings
Check for unsupported features:View Request Bodies
Inspect the actual request sent to the provider:Log Tool Calls
Monitor tool execution:Common Patterns
Few-Shot Prompting
Provide examples in your prompt:Chain of Thought
Ask the model to explain its reasoning:Role-Based Prompting
Assign the model a specific role:Constrained Generation
Use clear constraints:Tips Summary
General Prompts
- Be specific and clear
- Provide context and examples
- Use system messages to set behavior
- Add constraints when needed
- Request step-by-step reasoning for complex tasks
Tool Prompts
- Use strong models (GPT-5, Claude 4 Sonnet)
- Limit to 5 or fewer tools
- Use descriptive names and detailed descriptions
- Add
.describe()to all schema properties - Keep schemas simple and flat
- Document tool output formats
- Include example tool usage
Structured Data
- Add property descriptions
- Use
z.string().date()for dates, then transform - Use
.nullable()instead of.optional() - Set
temperature: 0for consistency - Provide output name and description
Debugging
- Check
result.warningsfor unsupported features - Inspect
result.request.bodyto see actual requests - Use callbacks to log tool calls and results
- Test with different models to compare behavior
Next Steps
Generating Text
Learn about text generation functions
Tool Calling
Master tool calling techniques
Structured Data
Generate type-safe structured data
Settings
Configure model parameters