Advanced Prompt Techniques: Using Instructions, Constraints, and Examples

Last updated on Oct 22, 2024 by Suraj Sharma



In this tutorial, you will learn about advanced prompt techniques, like using instructions, constraints, and examples. When I first started working with AI models, I often got responses that weren't exactly what I was looking for. Over time, I discovered that by refining my prompts using these techniques, I could get much better results.


Introduction

Prompt engineering is the art of crafting prompts to get the desired output from AI models like GPT-4o. By providing clear instructions, setting constraints, and including examples, you can guide the AI to produce more accurate and useful responses.


Using Instructions

Giving specific instructions in your prompt can help the AI understand exactly what you want.

Example 1:

Prompt:

"Write a short story about a robot learning to feel emotions."

AI Response:

Once there was a robot named Aiden who began to understand human emotions...


My Experience:

Initially, when I asked for stories, I got responses that were too long or didn't focus on the theme I wanted. By specifying that I wanted a "short story" and mentioning the theme ("robot learning to feel emotions"), I got a story that matched my expectations.

Improved Prompt with Instructions:

"Write a 500-word short story about a robot named Aiden who learns to feel emotions, focusing on his interactions with humans."

Now, the AI provides a story of the desired length and focuses on the aspects I care about.


Using Constraints

Constraints are limitations or specific requirements you include in your prompt to narrow down the response.

Example 2:

Prompt:

"List some healthy foods."

AI Response:

Fruits, vegetables, whole grains, lean proteins, nuts...


But if you're interested in foods that are high in protein:

Improved Prompt with Constraints:

"List five healthy foods that are high in protein suitable for vegetarians."

AI Response:

  1. Lentils
  2. Chickpeas
  3. Quinoa
  4. Tofu
  5. Greek yogurt

My Experience:

When planning my diet, I needed protein-rich vegetarian options. By adding constraints, I received a list that was tailored to my needs.


Providing Examples

Including examples in your prompt can guide the AI to produce responses in a specific format or style.

Example 3:

Prompt:

"Generate a list of study tips."

AI Response:

Study in a quiet place, take regular breaks, stay organized...


However, I wanted more detailed tips.

Improved Prompt with Examples:

"Generate a list of study tips. For example:
1. Use active recall by testing yourself on the material.
2. "

AI Response:

  1. Practice spaced repetition by reviewing notes over increasing intervals.
  2. Teach the material to someone else to improve understanding.
  3. Break study sessions into focused blocks of time (Pomodoro Technique).
  4. Create mind maps to visualize connections between concepts.

My Experience:

By providing an example, the AI continued the list in the format and level of detail I wanted.


Combining Techniques

You can also combine instructions, constraints, and examples for even better results.

Example 4:

Prompt:

"As a fitness coach, create a 3-day workout plan for beginners that requires no gym equipment. Include exercises targeting all major muscle groups."

AI Response:

Day 1:

  • Warm-up: 5 minutes of jogging in place
  • Exercises:
    • Push-ups: 3 sets of 10 reps
    • Bodyweight Squats: 3 sets of 15 reps
    • Plank: 3 sets of 30 seconds

Day 2:

  • Rest or light activity (e.g., walking)

Day 3:

  • Warm-up: 5 minutes of jumping jacks
  • Exercises:
    • Lunges: 3 sets of 10 reps each leg
    • Tricep Dips (using a chair): 3 sets of 12 reps
    • Mountain Climbers: 3 sets of 15 reps

My Experience:

I wanted to start exercising at home but wasn't sure how to structure my workouts. By combining instructions ("as a fitness coach"), constraints ("3-day workout plan", "no gym equipment"), and specifying the content ("exercises targeting all major muscle groups"), I got a practical plan to follow.


Tips for Using Advanced Techniques

  • Be Specific: Clearly state what you want, including any details that are important to you.

  • Set Clear Constraints: Use constraints like quantity, format, or specific criteria to narrow down the response.

  • Provide Examples: Show the AI the format or style you expect, so it can continue in the same way.

  • Combine Techniques: Don't hesitate to use instructions, constraints, and examples together for the best results.


Potential Challenges

  • Overcomplicating Prompts: Too many details or conflicting instructions can confuse the AI.

    Solution: Keep your prompts clear and focused. If necessary, break complex requests into smaller, separate prompts.

  • Ambiguity: Vague prompts can lead to unexpected results.

    Solution: Be as precise as possible to eliminate ambiguity.

My Experience:

Once, I asked:

"Create a plan for me."

The AI response was not useful because it didn't know what kind of plan I needed. Then I refined my prompt:

"Create a weekly meal plan that is vegetarian, budget-friendly, and includes breakfast, lunch, and dinner."

This time, the AI provided a detailed meal plan that met my requirements.


Wrapping Up

Using advanced prompt techniques like instructions, constraints, and examples can significantly improve the quality of responses you get from AI models. By taking the time to craft your prompts carefully, you can get more accurate and useful results tailored to your needs.

I hope you find this guide helpful! Let me know if you have any questions or comments.



Related Articles


Rate this post


Suraj Sharma is the founder of Future Gen AI Services. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.