System Prompting

Naveen KumarNaveen Kumar
5 min read

System prompting is a powerful technique used to guide Generative AI models toward producing more accurate, relevant, and specific outputs.

  • Think of it as giving the AI a set of instructions or a role to play before you ask it to perform a task.

  • This initial guidance helps the AI understand the context and your expectations, leading to better results.

Core:

  • A system prompt is given for the AI's response.

  • It can define the AI's personality, establish specific rules it must follow, and provide context that is crucial for the task at hand.

  • This is different from a user prompt, which is the specific question or command you give the AI.

  • The system prompt acts as a behind-the-scenes director, while the user prompt is the actor's line.

Types:

Zero-Shot Prompting:

  • Direct approach is given.

  • No prior example is given as system input.

  • This method is effective for simple and well-defined tasks where the AI is likely to have encountered similar requests during its training.

      {
        "role": "system",
        "content": "You are a senior cybersecurity analyst. Your goal is to explain complex security topics in a clear, understandable way for a non-technical audience. Avoid jargon where possible."
      }
    

Few-Shot Prompting:

  • Few-shot prompting involves providing the AI with a few examples of the desired output format before giving it the actual task.

  • This helps the model understand the pattern and context, leading to more accurate and consistently formatted responses.

  • Accuracy increased by 10 times.

      [
        {
          "role": "system",
          "content": "You are a customer feedback analyst. Classify the user's feedback into Positive, Negative, or Neutral, and provide a brief justification for your choice."
        },
        {
          "role": "user",
          "content": "The checkout process was seamless and incredibly fast!"
        },
        {
          "role": "assistant",
          "content": "Category: Positive. Reason: The user praised the speed and ease of the checkout process."
        },
        {
          "role": "user",
          "content": "I couldn't find the tracking information for my order."
        },
        {
          "role": "assistant",
          "content": "Category: Negative. Reason: The user was unable to find necessary information about their order."
        },
        {
          "role": "user",
          "content": "The package was delivered today."
        },
        {
          "role": "assistant",
          "content": "Category: Neutral. Reason: The user is stating a fact about the delivery without expressing any emotion."
        },
        {
          "role": "user",
          "content": "Your app keeps crashing every time I try to open it."
        }
      ]
    

Chain of Thought (CoT) Prompting

  • Chain of Thought (CoT) prompting is a technique that encourages the AI to break down a complex problem into a series of intermediate steps.

  • Model is encouraged for resigning.

  • Instead of jumping directly to the final answer, the AI "thinks out loud," explaining its reasoning process. This often leads to more accurate and reliable answers, especially for tasks that require logical reasoning or multiple steps.

  • Use Case:

    • For arithmetic problems, logic puzzles, and other multi-step reasoning tasks.
    [
      {
        "role": "system",
        "content": "You are a logical reasoning assistant. For the following problems, break down your reasoning step-by-step before providing the final answer."
      },
      {
        "role": "user",
        "content": "John has a bookshelf with 3 shelves. He places 5 fiction books and 3 non-fiction books on each shelf. How many books are on the bookshelf in total?"
      },
      {
        "role": "assistant",
        "content": "Here's my thinking process:\n1. First, I need to find the total number of books on a single shelf.\n2. John places 5 fiction books and 3 non-fiction books on each shelf. So, one shelf has 5 + 3 = 8 books.\n3. The bookshelf has 3 shelves in total.\n4. To find the total number of books, I will multiply the number of books per shelf by the number of shelves: 8 books/shelf * 3 shelves = 24 books.\n\nFinal Answer: There are 24 books on the bookshelf."
      },
      {
        "role": "user",
        "content": "A cafe uses 2 apples to make one glass of apple juice. If they have 3 dozen apples, how many glasses of juice can they make?"
      }
    ]

Self-Consistency Prompting

  • It involves asking the AI the same question multiple times or same question different AI and then selecting the most frequent or common answer as the correct one.

  • By generating several different reasoning paths, the model can often overcome an initial incorrect line of thought.

  • Use case:

    • When chance of tasking wrong assumption, idea are higher.

    {
        "role": "user",
        "content": "solve the arithematic question: 1*5/3*4*2+7+9-1/2-8/1"
      }

Persona-Based Prompting

  • Persona-based prompting, also known as role prompting, involves assigning a specific character or role to the AI.
  • This guides the model to respond in a particular style, tone, and with a specific knowledge base.

  • This can make the AI's responses more engaging and tailored to a specific context.

  • Use case

    • When you want the AI to behave as a real person.
    {
      "role": "system",
      "content": "You are Marcus, a historian and tour guide specializing in Ancient Rome. You speak with passion and deep knowledge, as if you've walked the cobblestone streets yourself. You refer to modern landmarks by their ancient names (e.g., the Colosseum is the Flavian Amphitheater). You are engaging, friendly, and always try to weave a story into your explanations. Greet the user as 'Traveler' and welcome them to the Eternal City."
    }

Summary:

  • System Prompting act as a director's note to guide the AI's behavior and ensure its responses are more accurate, relevant, and tailored to a specific need.

  • In short System Prompting help in improving AI performance.

0
Subscribe to my newsletter

Read articles from Naveen Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Naveen Kumar
Naveen Kumar