Master the art of writing effective prompts to get better, more consistent results from AI models.
Prompt engineering is the practice of designing inputs that guide AI models to produce desired outputs. A well-crafted prompt can dramatically improve the quality, accuracy, and usefulness of AI responses.
Tell the model exactly what you want it to do. Ambiguity leads to inconsistent results.
Include relevant constraints, format requirements, and context for better outputs.
Show the model what good output looks like with one or more examples.
Refine your prompts based on results. Small changes can have big impacts.
Vague prompts get vague answers. The more specific you are about what you want, the better the results.
Include details like: format (list, paragraph, JSON), length (word count, number of items), tone (professional, casual, technical), and audience (beginners, experts, children).
Context helps the model understand your situation and provide relevant responses.
The system message sets the overall behavior and context for the conversation:
response = client.chat.completions.create(
model="mythic-4",
messages=[
{
"role": "system",
"content": """You are a helpful customer support agent for TechCorp.
- Always be polite and professional
- If you don't know an answer, say so honestly
- For billing issues, direct users to billing@techcorp.com"""
},
{
"role": "user",
"content": "How do I reset my password?"
}
]
)
Show the model what you want by including examples in your prompt. This is especially useful for specific formats or styles.
Start with 2-3 examples. More examples improve consistency but use more tokens. For simple tasks, even 1 example often works well.
Request specific output formats for easier parsing and more consistent results.
Extract the following information from this text and return as JSON: - person_name: The person's full name - company: Their company name - role: Their job title - email: Their email address (or null if not found) Text: "Hi, I'm Sarah Chen, Product Manager at Acme Corp. Reach me at sarah@acme.com."
Clear delimiters help the model understand where different parts of your prompt begin and end:
Summarize the text between the triple backticks in one sentence. ``` The quick brown fox jumps over the lazy dog. This sentence contains every letter of the alphabet and is often used for typing practice and font demonstrations. ```
Ask the model to think step-by-step for complex reasoning tasks:
Assign a specific role or persona for specialized responses:
Break complex tasks into multiple prompts for better results: