Introduction: Why Iterative Prompting Matters

Welcome back! In previous lessons, you learned how to craft effective prompts and how system prompts can guide a language model's behavior. Now, let's take your skills further by exploring iterative prompting.

Iterative prompting is a technique where you build and refine your prompts step by step, using the model's responses to guide your next move. This approach is especially useful when you want more control over the output or are unsure exactly what you want at the start. By working in small steps, you can achieve clearer, more useful results from the model.

What Is Iterative Prompting?

Iterative prompting means you don't have to get your prompt perfect on the first try. Instead, you start with a simple prompt, review the model's response, and then use that output to improve your next prompt. This differs from single-shot prompting, where you try to get everything you want in one go. Here's a quick comparison:

Single-shot prompting:

  • Write 5 fun math quiz questions for 5th grade students.
  • Model's answer

Iterative prompting:

  • Write 5 fun math quiz questions for 5th grade students.
  • Model's answer
  • Make the questions a bit harder; these are too easy.
  • Model's answer
  • Make the questions more diverse. Include other question formats. Keep the current difficulty; it is good.
  • Model's answer

This method is similar to conversing with a colleague: you ask a question, get an answer, and then ask follow-up questions or clarify your request based on their response.

Iterative Prompt Refinement

Another way to use iterative prompting is to refine your original prompt based on the model's output. For example, suppose you want the model to generate 5 fun math questions, but you also want the answers formatted in a specific way. Providing a formatting example is best, but creating one from scratch can be time-consuming.

Instead, you can use the model's initial output as a base for your example.

First, ask the model to generate questions:

The model might reply:

You can copy and refine this output to create a formatting example for your following prompt. This is often faster than writing an example from scratch. Here's how your improved prompt might look in a new chat:

This step-by-step process can be much more time-efficient than writing your prompt from scratch.

Using the Model for Context and Clarification

Iterative prompting is also helpful when you're unsure how to phrase your request or need more background before making your main ask. In these cases, you can use the model to help you build context.

Step 1: Ask for an Explanation

Suppose you want to create a quiz about photosynthesis, but you're not confident about the details. Start by asking the model for an explanation:

The model might respond:

Step 2: Use the Explanation to Guide Your Next Prompt

Now, use this explanation to create a more focused prompt:

Why does this work?
By first asking for an explanation, you ensure the model understands the topic, and you get the context you need. Then, you can use that context to make your main request, leading to more accurate and relevant results.

Summary and What's Next

In this lesson, you learned how to use iterative prompting to build better prompts step by step. You saw how starting with a simple prompt, using the model's output as an example, and asking for context or clarification can help you get more precise and helpful responses.

Next, you'll get a chance to practice these techniques yourself. Try building prompts step by step, refining your requests, and using the model's answers to guide your next move. This hands-on practice will help you master iterative prompting and make your interactions with language models even more effective.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal