Prompt engineering is the practice of designing and optimizing input prompts to get the best possible outputs from Large Language Models.
Prompt engineering involves:
we saw how the transformer allows to “soak” the context.
Therefore, the more relevant and specific context we provide, the better the results.
Read more about this topic from OpenAI Prompt Engineering Guide or the Best Practices for OpenAI API
Since the transformers “soaks” context, the more the better. Consider this examples:
You can add more context like:
Assign the AI a specific role or persona:
"You are an experienced software engineer.
Review this code and suggest improvements for performance and readability."
"Act as a patient teacher explaining quantum physics to a high school student."
Provide examples of desired input-output pairs:
Classify these emails as spam or not spam:
Email: "Congratulations! You've won $1,000,000!"
Classification: Spam
Email: "Meeting moved to 3 PM tomorrow"
Classification: Not Spam
Email: "Click here for amazing weight loss secrets!"
Classification: Probably Spam
Guide the model through step-by-step reasoning:
We need to choose between holding our workshop in-person or online.
Analyze this decision step by step:
Step 1: List key factors to consider (costs, accessibility, engagement, logistics)
Step 2: Evaluate each format against these factors
Step 3: Identify the main trade-offs
Step 4: Recommend the best option with justification
math problems are poorly managed in general, and a good alternative is to ask to generate
code to solve the problem instead.
Specify exactly how you want the response structured:
Analyze this meeting summary and structure your response as:
Key Decisions
- [list decisions made]
Action Items
- [person]: [task] - [deadline]
Open Questions
- [questions requiring follow-up]
Use markdown formatting with these exact headings.
Explore multiple reasoning paths:
"Consider three different approaches to solve this problem:
Approach 1: [method]
Approach 2: [method]
Approach 3: [method]
Evaluate each approach and recommend the best one."
Include principles and values:
"Provide advice on this ethical dilemma. Consider:
- Respect for individual autonomy
- Minimizing harm to all parties
- Fairness and justice
- Long-term consequences
..."
Explicitly state what to avoid:
"Write a product description that:
- Highlights key features
- Uses simple language
- Avoids technical jargon
- Does not make exaggerated claims
- Is under 100 words"
Example of structured prompt:
[ROLE] You are a [specific role]
[CONTEXT] Given this context: [background information]
[TASK] Your task is to: [specific instruction]
[FORMAT] Provide the output in this format: [format specification]
[CONSTRAINTS] Requirements: [limitations and guidelines]
A template for an analysis:
"Analyze the following [content type]:
[CONTENT]
Provide:
1. Summary (2-3 sentences)
2. Key insights (3-5 bullet points)
3. Recommendations (specific actions)
4. Potential concerns or limitations
Focus on [specific aspect] and consider [context]."
An example of creative writing:
"Write a [content type] that:
- Genre: [specify genre]
- Audience: [target audience]
- Tone: [desired tone]
- Length: [word count]
- Key elements to include: [list]
- Style: [writing style preference]"
"Write a Python function that:
- Function name: calculate_compound_interest
- Parameters: principal, rate, time, compound_frequency
- Returns: final amount
- Include: type hints, docstring, error handling
- Style: Follow PEP 8 conventions"
"Analyze this dataset:
[DATA]
1. Identify data types and structure
2. Find patterns and trends
3. Detect outliers or anomalies
4. Suggest visualization approaches
5. Recommend next analysis steps"