Getting Good at Talking to AI: Why One Way Doesn't Work for All - Development Diary and Discussion

Mastering the Art of Prompting: Why One Size Doesn't Fit All in the World of AI Agents

It's a common mistake to use the exact same instructions (called "prompts") for different big language models (LLMs). Just like different people learn in different ways, different AI models are trained in their own special ways. This means the best way to talk to one might not be the best way to talk to another. This blog post will help you understand the different ways to give instructions to AI, whether you're just starting out or you already have some experience.

Who This Blog Post Is For:

  1. People who are new to giving instructions to AI and want to learn the basics.
  2. People who want to share ideas and learn more about how to give the best instructions.

Understanding the Basics of Giving Instructions (Prompting)

Basically, prompting is how you tell an AI model what you want it to do. There are generally two main ways to do this:

  • Zero-Shot Prompting: This is like asking a question without giving any examples. You just give the AI one set of instructions and expect it to give you the answer you want.

  • One-Shot/Few-Shot Prompting: This is when you give the AI one or a few examples along with your instructions to show it what you're looking for. It's like saying, "Do something like this..." before asking it to do its own thing.

Let's look at how this works with an example of a tool built by us that makes resumes (Resume Generator). We'll see how the instructions we give might be different when we use a Google AI model called Gemini.


Zero-Shot Prompting with Gemini (Resume Generator Example)

If we're using zero-shot prompting for our Resume Generator, we put all the instructions into one single prompt:

Given my background and what the job is asking for, create a resume that fits the job.
""" My Background
Short info about my work history
"""
""" Job Description
What the job ad says
"""
Here's what the resume needs to have:
1. Include specific skills mentioned in the job description.
2. Show off the things I've done in the past that can be measured.
3. Make the resume look clean and professional.

Here, we give all the information and tell the AI exactly what we want in one go. We're hoping Gemini understands enough to create a good resume.

Multi-Shot Prompting in Action: The Resume Generator Example

Now, let's look at how we can give instructions in steps (multi-shot prompting) with our Resume Generator. Instead of one big instruction, we send a few messages one after the other in the same conversation to guide the AI.

Here's an example of the steps we might take with the Gemini model (you can see this in the code below):

Dart

return chat
        .sendMessage(
          Content.text(
            '''
You are helping me write a resume. First, read and understand my background info in this data.
'${jsonEncode(Provider.of<DataProvider>(context, listen: false).backgroundInfo)}'
Wait for my next instruction before you do anything.
            ''',
          ),
        )
        .then((_) {
      updateLoadingMessage('Looking at what the resume needs...');
      return chat.sendMessage(Content.text(prompt)).then((_) {
        updateLoadingMessage('Creating the resume content...');
        return chat.sendMessage(Content.text('''
Now, finish writing the resume using these rules:
1. Focus on the background info that matches what the job needs.
2. Use the important words from the job description to explain my background info.
3. Make the resume specific to this job.
4. Use only the background info I gave you.
5. Point out any preferred skills I have.
6. For each job I've had, write about what I did using this format: "Achieved [X] by [Y], by doing [Z]."
7. Show numbers and amounts to prove what I did.
8. Use strong action words.
9. Make it one or two pages long.
10. List everything in each section from newest to oldest.
          ''')).then((_) {
            updateLoadingMessage('Resume is done!');
            return chat;
          });
        });
      });
    }

Reference: https://github.com/jeff214103/resume-generator/blob/main/lib/screen/generate.dart

As you can see, we talk to the AI in a few steps:

  1. First, Understand My Background: We tell the AI to read and understand my work history (which is probably in a special data format called JSON) and wait for more instructions.
  2. Then, Consider the Job Needs: The prompt (which we don't see all of here) likely contains the job description and some general things the resume needs. We send this in the second message.
  3. Finally, Follow These Detailed Rules: The last message gives very specific rules on how to write and format the resume, using my background info and making it right for the job.

This step-by-step way of giving instructions can give us more control over how the resume is created compared to just giving one big instruction at the start.

Multi-Shot Prompting with Claude: Helping It Think Step-by-Step

For another AI model called Claude, multi-shot prompting can be used in a different way. Instead of just giving examples of what we want, we can actually tell Claude how to think to get the best answer:

Please think about this math problem very carefully and in lots of detail.
Think of different ways to solve it and show all your thinking.
If the first way doesn't work, try other ways.

Reference: https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/extended-thinking-tips

This way of prompting encourages Claude to think more deeply and logically, which can lead to better answers.

DeepSeek's Special Way: Using the <thinking> Tag

The way another AI model called DeepSeek thinks is different again. Instead of us having to tell it to think, DeepSeek sometimes uses special tags like <thinking> to show its own thought process:

Python
# Tell the AI what we want it to do.
prompt = "Describe what a 'hello world' program does in one line."

# Put the instruction in DeepSeek's special format.
formatted_prompt = f"""
<|begin of sentence|><|User|>{prompt}<|Assistant|><think>\n
"""

Reference: https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-deepseek.html

Also, DeepSeek might give back answers in a format that's different from other AI models.

The Important Point: Don't Use the Same Instructions for Every AI


The examples above show us something important: it's usually not the best idea to use the exact same instructions for all different AI models. Each model is built and trained differently, which means they understand and respond to instructions in their own way.

Think about AI tools that are made for specific things, like Windsurf or Cursor. If you just use general instructions with them, you might not get the best out of what they can do.

Beyond Just Giving Instructions: Understanding How AI Gives Answers


The differences between AI models aren't just about how they understand instructions; it's also about how they give back their answers. In many cases, especially when we're using AI to change messy data into organized data, it's important to control how the AI formats its answer.

For example, with our Resume Generator, we might want to take someone's school records (which might be messy) and turn them into a clean, organized format called JSON so it's easier to use. Or, a tool that tracks expenses might use AI to read a picture of a receipt and turn it into a JSON format.

Different AI models have different ways of making sure their answers are in the format you want:

  • Gemini: You can often tell it what kind of data format you want (like a specific file type).
  • Claude: You can tell it in plain language to make sure its answer is in a specific format, like JSON.

Understanding what each AI model can do with its output is important for using them effectively in your projects.

Conclusion: Getting to Know Each AI Model

Giving instructions to AI is more than just telling it what to do. It's about learning how each AI model works, what it's good at, and how it likes to be talked to. Think of it as making friends with each one.

Because different companies train their AI models in different ways, you'll see big differences in how they respond to the same instructions. Also, the best way to give instructions today might not be the best way tomorrow as these models keep getting better.

In the end, becoming good at prompting means trying things out and seeing what works best for each AI model. The goal is to find ways to give instructions that will give you good results consistently, even if you ask the same thing hundreds or thousands of times. This kind of reliable result is possible if you practice and are willing to change your approach for each different AI.



Comments

Popular posts from this blog

Resume Generator - Software Intro

Build AI Code Generation Tools For Large Scale Project in Python? Part 1 - Development Diary and Discussion

Expense Tracker - Software Intro