- What task to perform
- What context to consider
- How specific the response should be
- What constraints to follow
- What format the output should use
1. Role Prompting
Definition
Role prompting means assigning a role, expertise, or perspective to the LLM. This helps guide the style, depth, and perspective of the response.Example
Another Example
Why It Is Useful
Role prompting can help control:- Level of expertise
- Writing style
- Perspective
- Type of explanation
- Expected vocabulary
Template
2. Context
Definition
Context is the relevant background information provided to the model before or along with the task. More relevant context usually helps the model produce a more appropriate answer.Example Without Context
Example With Context
Why Context Is Important
Context helps the model understand:- The user’s situation
- The target audience
- The domain
- Previous decisions
- Important requirements
- Relevant input data
Template
3. Specificity
Definition
Specificity means clearly defining exactly what you want the model to do. A vague prompt can produce vague or unpredictable results.Vague Prompt
Specific Prompt
Benefits
Specific prompts help:- Reduce ambiguity
- Improve relevance
- Control response length
- Avoid unnecessary information
- Produce more predictable results
4. Constraints
Definition
Constraints are rules or limitations that control the model’s response. They define what the model should or should not do.Example
Common Constraints
- Maximum word count
- Minimum number of examples
- Required sections
- Language level
- Tone
- Topics to avoid
- Output length
- Formatting rules
Example
5. Output Format
Definition
Output format specifies how the LLM should structure its response. This is useful when you need consistent and predictable results.Example
JSON Example
Why It Is Useful
Output formatting helps:- Create consistent responses
- Make results easier to read
- Support automation
- Enable easier parsing by applications
- Improve integration with software systems
6. Zero-Shot Prompting
Definition
Zero-shot prompting means giving the model a task without providing examples. The model uses its existing knowledge and the instructions in the prompt.Example
When to Use
Use zero-shot prompting when:- The task is simple
- The instructions are clear
- Examples are not necessary
- You want a short and efficient prompt
7. Few-Shot Prompting
Definition
Few-shot prompting means providing a few examples to demonstrate the expected task or output. The examples guide the model.Example
When to Use
Few-shot prompting is useful when:- The task has a specific pattern
- Output formatting is important
- The classification criteria are unclear
- You want consistent behavior
Important Point
The examples should be:- Relevant
- Clear
- Consistent
- Similar to the actual task
8. Reasoning and Verification
Definition
Some tasks are complex and benefit from explicitly asking the model to carefully reason through the problem and verify the result. This is especially useful for:- Mathematics
- Programming
- Data analysis
- Multi-step problems
- Logical reasoning
Example
Verification Prompt
Important Practice
For important tasks, ask the model to:- Solve the task.
- Check the result.
- Compare the result with the requirements.
- Correct any identified problems.
9. Structured Output
Definition
Structured output means requesting the model to return information in a predefined, machine-readable format. Common formats include:- JSON
- CSV
- XML
- YAML
- Tables
JSON Example
Example Output
Benefits
Structured output makes it easier to:- Store responses
- Parse data
- Use responses in APIs
- Connect LLMs with applications
- Automate workflows
10. Iterative Refinement
Definition
Iterative refinement means improving a prompt or output through multiple attempts. Instead of expecting the first prompt to be perfect, you evaluate the result and improve the instructions.Example
First Prompt
Improved Prompt
Further Refinement
Iterative Process
11. Self-Evaluation
Definition
Self-evaluation means asking the model to evaluate its generated output against predefined criteria.Example
Benefits
Self-evaluation can help improve:- Completeness
- Consistency
- Formatting
- Requirement compliance
- Error detection
Evaluation Template
12. Prompt Chaining
Definition
Prompt chaining means breaking a complex task into multiple smaller stages. The output from one stage can become the input for the next stage.Example: Writing an Article
Instead of using one large prompt:Step 1: Generate Topics
Step 2: Create an Outline
Step 3: Write the Content
Step 4: Review
Workflow
Benefits
Prompt chaining helps with:- Complex tasks
- Large documents
- Multi-step workflows
- Better control
- Easier debugging
13. Context Management
Definition
Context management is the process of selecting, organizing, and maintaining the information given to an LLM. LLMs have limits on how much information can be processed in a request. Therefore, irrelevant or excessive context should be avoided.Poor Context Management
Better Context Management
Context Management Techniques
1. Include Relevant Information
Only provide information related to the task.2. Remove Unnecessary Information
Avoid including unrelated files, messages, or data.3. Summarize Long Content
4. Retrieve Relevant Information
For large knowledge bases:14. Prompt Templates
Definition
A prompt template is a reusable prompt structure containing placeholders or variables.Example
15. Prompt Variables
Definition
A prompt variable is a placeholder whose value can change dynamically.Template
Variable Values
Final Prompt
16. Prompt Templates and Variables in Python
17. Delimiters
Definition
Delimiters are symbols or markers used to clearly separate instructions, context, and input. They help organize complex prompts. Common delimiters include:Example
Why Delimiters Are Useful
They help separate:- Instructions
- User input
- Examples
- Data
- Context
18. Task Decomposition
Definition
Task decomposition means breaking a large problem into smaller and manageable tasks.Example
Instead of:Benefits
- Easier problem solving
- Better control
- Easier debugging
- Clearer workflow
- Improved reliability
19. Input Data Separation
When providing external data, clearly separate the instructions from the data.Example
- Instructions
- Input data
- Examples
- User-generated content
- Web content
- Documents
- Emails
- Retrieved knowledge
20. Negative Instructions
Definition
Negative instructions specify what the model should avoid doing.Example
Example
21. Audience Targeting
The same information can be explained differently depending on the audience.Example
Beginner
Developer
- Vocabulary
- Technical depth
- Examples
- Explanation style
22. Prompt Ordering
The order of information in a prompt can improve clarity. A recommended structure is:Example
23. Instruction Hierarchy
When a prompt contains multiple instructions, organize them clearly.Poor Example
Better Example
24. Handling Ambiguity
If a task is unclear, the prompt can instruct the model how to handle missing information.Example
25. Grounding
Definition
Grounding means instructing the model to base its response on specific provided information.Example
Why Grounding Is Useful
It helps:- Reduce unsupported claims
- Keep answers relevant
- Improve consistency
- Support document-based question answering
26. Prompt Injection Awareness
When an LLM processes external or untrusted content, that content may contain instructions that attempt to change the task.Example
- Trusted instructions
- Untrusted input data
- Web content
- User input
- Documents
- RAG systems
- External APIs
27. Temperature and Generation Settings
When using an LLM API, generation settings can affect the output.Temperature
Temperature controls the level of randomness in generated responses.Lower Temperature
- Structured extraction
- Classification
- Consistent answers
- Deterministic-style tasks
Higher Temperature
- Creative writing
- Brainstorming
- Generating ideas