Prompting Basics

Su Suriya Ravichandran Updated 28 Oct 2026
13 min read ·Lesson 3 of 3

The Basic Prompt Pattern

Almost every useful prompt, no matter how simple, answers three questions for the model:

1. Task    → What should be done?
2. Details → What specifics, limits, or background matter?
3. Format  → What should the answer look like?

You do not always need all three. A simple factual question may only need the task. But when a response is disappointing, the cause is usually that one of these three was missing or unclear.

Example: Building a Prompt With the Basic Pattern

Task only:

Explain what an API is.

Task + details:

Explain what an API is to a small business owner who has no technical background.
Use one example from online shopping.

Task + details + format:

Explain what an API is to a small business owner who has no technical background.
Use one example from online shopping.
Keep it under 100 words and write it as a single paragraph.

Example Explanation

VersionWhat the Model Must GuessTypical Result
Task onlyAudience, depth, length, formatA generic, often technical explanation
Task + detailsLength and formatA relevant explanation, but length varies
Task + details + formatVery littleA focused, predictable answer that fits its purpose

Each addition removes one area of guessing. This is the foundation that every technique in this tutorial builds on.


Four Basic Styles of Prompts

Prompts can be written in different styles. Each style signals a different kind of response.

1. Question Prompts

A question asks for information.

What is the difference between a list and a tuple in Python?

When to use: Factual lookups, explanations, quick clarifications. Limitation: A bare question leaves depth, audience, and format to the model. Add details when those matter.

2. Instruction Prompts

An instruction tells the model to perform a task.

Rewrite the following sentence to sound more professional:
"hey, can u send me the files asap?"

When to use: Transforming text, generating content, analyzing input. Most practical prompts are instructions. Why it works well: Instruction-following models are trained specifically on instruction-and-response examples, so a clear command maps directly to the behavior they learned.

3. Completion-Style Prompts

A completion-style prompt provides the beginning of the desired output and lets the model continue.

Product: Wireless noise-cancelling headphones
Target customer: Students studying in noisy dorms
Tagline:

When to use: When you want a very specific structure and want the model to fill in one slot. The labels make the expected output obvious. Why it works: As explained in Lesson 2, models predict what comes next. Ending a prompt with Tagline: makes a short tagline the most natural continuation.

4. Conversational Prompts

A conversational prompt continues a dialogue and relies on earlier messages.

That explanation was helpful. Can you give me a code example of the same idea?

When to use: Refining or extending a previous answer in a chat. Limitation: It only works when the earlier messages are part of the context. On its own, "the same idea" has no meaning.

Comparison

StyleSignal to the ModelBest ForRisk
Question"Provide information"Explanations and factsUnpredictable depth and length
Instruction"Perform this task"Most practical workVague verbs lead to vague results
Completion"Continue this pattern"Fixed structures, short outputsLess suited to complex tasks
Conversational"Build on what came before"Refinement in chatFails without history

In practice, prompts often combine styles. An instruction followed by a labeled output slot (Answer:) is a very common and effective combination.


A Tour of Basic Prompting Tasks

LLMs can perform many kinds of tasks with simple prompts. The following examples show the most common categories. Each category has its own lessons later in the series; here the goal is to recognize them and see a correct basic prompt for each.

Summarization

Summarize the following paragraph in one sentence:
"Django is a high-level Python web framework that encourages rapid development
and clean design. It includes built-in features for authentication, database
access through an ORM, an admin interface, and security protections against
common attacks, so developers can focus on their application instead of
rebuilding common components."

Possible output:

Django is a Python web framework that speeds up development by providing
built-in tools such as authentication, an ORM, an admin panel, and security features.

Explanation: The instruction defines the task (summarize) and a hard limit (one sentence). Without the limit, a "summary" could be almost as long as the original.

Information Extraction

Extract the course name and price from this text.
Text: "Enroll now in the Full-Stack MERN Bootcamp for just ₹4,999 and start building real projects."
Course name:
Price:

Possible output:

Course name: Full-Stack MERN Bootcamp
Price: ₹4,999

Explanation: The empty labels at the end act as a completion-style template. The model fills each slot, which makes the output easy to read and easy for code to parse.

Question Answering

Answer the question using only the information in the text.
If the answer is not in the text, reply "Not mentioned."
Text: "The internship runs for 8 weeks and is open to final-year students."
Question: Is the internship paid?

Possible output:

Not mentioned.

Explanation: The text says nothing about payment. Because the prompt provides an explicit response for missing information, the model has an acceptable answer that does not require guessing.

Text Classification

Classify the sentiment of this review as Positive, Negative, or Neutral.
Review: "The videos were clear, but the quizzes had many mistakes."
Sentiment:

Possible output:

Neutral

Explanation: Listing the allowed labels restricts the answer. Mixed reviews are a common edge case; some models may choose Negative here. If you need a specific rule for mixed opinions, state it, for example: "If a review contains both positive and negative points, classify it as Neutral."

Conversation and Role

You are a friendly assistant for a coding bootcamp. Answer questions from
prospective students in a warm, encouraging tone, in no more than three sentences.
Student: I am 35 and have never coded. Is it too late to start?
Assistant:

Explanation: The first paragraph defines the assistant's role, tone, and length. The Student: / Assistant: labels set up a dialogue, and the open Assistant: slot tells the model whose turn it is.

Code Generation

Write a Python function named is_valid_email that returns True if a string
contains exactly one "@" and at least one "." after the "@", otherwise False.
Do not use regular expressions. Include a docstring.

Possible output:

def is_valid_email(value: str) -> bool:
    """Return True if value has exactly one '@' and a '.' after it."""
    if value.count("@") != 1:
        return False
    local_part, domain = value.split("@")
    return bool(local_part) and "." in domain

Explanation: The prompt specifies the function name, exact rules, a restriction (no regular expressions), and a documentation requirement. Notice that the model also added a reasonable check that the part before @ is not empty. Generated code may include such assumptions, which is why you must always read and test it. Also note that this simple rule is not full email validation; the prompt asked for a specific simple check, and the result is only as complete as the rule you described.

Reasoning

A course costs ₹2,000. There is a 25% discount, and then 18% GST is added
to the discounted price. What is the final price?
Show each calculation step, then give the final answer on its own line.

Possible output:

Discount: 25% of 2,000 = 500
Discounted price: 2,000 - 500 = 1,500
GST: 18% of 1,500 = 270
Final price: 1,500 + 270 = 1,770
Final answer: ₹1,770

Explanation: Asking the model to show its steps makes multi-step calculations more reliable and lets you verify each step. This idea is developed fully in the Chain-of-Thought lessons.


Prompting in a Chat vs Prompting in Code

The same prompt can be used in a chat tool or sent from a program. The difference is how the parts of the prompt are delivered.

In a Chat Interface

You type everything into the message box. Instructions and data are in the same message:

Classify the sentiment of this review as Positive, Negative, or Neutral.
Review: "Great mentors and practical projects."

In Code

In an application, the fixed instructions are usually separated from the changing user content.

from openai import OpenAI
client = OpenAI()
MODEL = "gpt-5.4"  # Replace with a model available in your account
INSTRUCTIONS = (
    "Classify the sentiment of the review as Positive, Negative, or Neutral. "
    "If the review contains both positive and negative points, use Neutral. "
    "Reply with the label only."
)
def classify_review(review: str) -> str:
    response = client.responses.create(
        model=MODEL,
        instructions=INSTRUCTIONS,
        input=f"Review: {review}",
    )
    return response.output_text.strip()
reviews = [
    "Great mentors and practical projects.",
    "The certificate took three weeks to arrive.",
    "Good content, but the audio quality was poor.",
]
for review in reviews:
    print(classify_review(review), "-", review)

Possible output:

Positive - Great mentors and practical projects.
Negative - The certificate took three weeks to arrive.
Neutral - Good content, but the audio quality was poor.

Code Explanation

  • INSTRUCTIONS contains the parts of the prompt that never change: the task, the allowed labels, the rule for mixed reviews, and the format rule.
  • input=f"Review: {review}" contains only the part that changes for each call.
  • .strip() removes any leading or trailing whitespace or newlines so the label can be compared reliably in code.
  • The loop sends three separate requests. Each request is independent (Lesson 2), so each must contain the full instructions, which the instructions parameter handles automatically. Why separate them? The same instructions are reused for every review, so they are written once and tested once. User text stays clearly separate from your rules, which makes the prompt easier to maintain and safer against user text that tries to change the model's behavior.

    Reading and Checking a Response

    Writing the prompt is only half of prompting. The other half is evaluating what came back. Check every important response against these questions: | Check | Question to Ask | If It Fails | |-------|-----------------|-------------| | Task | Did it do what I asked, or something similar but different? | Make the task verb more precise | | Completeness | Did it cover everything I required? | List the required points explicitly | | Format | Is the structure and length what I asked for? | Specify format more concretely, or show an example | | Accuracy | Are the facts, numbers, and code correct? | Provide source information; verify independently | | Assumptions | Did it assume things I did not say? | Add the missing details to the prompt | | Extras | Did it add things I did not want, such as introductions or disclaimers? | State what to leave out | The Assumptions check is especially useful. When a response is wrong in a consistent way, it usually reveals information you knew but did not include.


    Follow-Up Prompts

    In a chat, you rarely get the perfect answer on the first attempt. Follow-up prompts let you refine the result without starting over.

    Effective Follow-Ups Are Specific

    Weak Follow-UpBetter Follow-Up
    Make it better.Make the second paragraph shorter and replace the technical terms with plain language.
    That's wrong.The price calculation is wrong: GST should be applied after the discount, not before. Please recalculate.
    More examples.Add two more examples, one from banking and one from food delivery.

    A specific follow-up tells the model what to change and how. A vague follow-up forces it to guess what "better" means, which often changes parts you were already happy with.

    When to Start a New Conversation

    Follow-ups work well for refining one task. Start a new conversation when:

  • You are switching to an unrelated task.
  • The conversation has many failed attempts, and the model keeps repeating earlier mistakes.
  • The conversation is very long, and early details are being lost. Every message in the conversation becomes context for the next answer, so a cluttered history can pull responses in unwanted directions. A fresh conversation with one well-written prompt often works better than ten corrections.

    From Follow-Ups to Better First Prompts

    When you notice yourself making the same follow-up repeatedly, such as "make it shorter" or "use simpler words", add that requirement to your original prompt. Over time, follow-ups become a way to discover what your first prompt was missing. Lesson 12 develops this into a structured iteration process.


    Common Mistakes

    Mistake 1: Asking Without Saying Why

    What it is: A prompt such as List some Python libraries. with no purpose. Why it happens: The purpose feels obvious to the writer. What it causes: A generic list that may not suit your goal (web development, data science, or automation). How to fix it: Add the purpose: List 5 Python libraries for building REST APIs, with one sentence on when to choose each.

    Mistake 2: Using Conversational Prompts Without Context

    What it is: Sending "Do the same for the next one" in a new conversation or a new API call. Why it happens: Forgetting that models are stateless. What it causes: The model has no idea what "the same" refers to. How to fix it: Restate the task, or ensure the previous messages are included.

    Mistake 3: Accepting the First Response Without Checking

    What it is: Copying output directly into an article, email, or codebase. Why it happens: Responses are fluent and look finished. What it causes: Factual errors, wrong code, or tone that does not fit the audience. How to fix it: Use the response checklist above, and test any generated code.

    Mistake 4: Leaving the Label Set Open in Classification

    What it is: Asking "What is the sentiment?" without listing allowed answers. Why it happens: It seems obvious that sentiment is positive or negative. What it causes: Answers such as "Mostly positive with some concerns", which code cannot handle. How to fix it: List the allowed labels and define how to handle borderline cases.


    Best Practices

    Use the task–details–format pattern as your default. Start every non-trivial prompt by asking what should be done, what matters, and what the answer should look like. Prefer instructions over bare questions for practical work. "Explain X to Y in Z words" gives more control than "What is X?" Use labels to guide structure. Labels such as Text:, Question:, and Answer: clearly separate input from output and make the expected continuation obvious. Tell the model what to do when information is missing. A rule such as If it is not mentioned, reply "Not mentioned." prevents guessing. Keep fixed instructions separate from changing data in code. Use the API's instruction or system channel for rules, and pass user content separately. Turn repeated follow-ups into prompt improvements. If you always need to correct the same thing, fix it in the original prompt.


    Try It Yourself

    Exercise 1: Apply the Basic Pattern

    Start with this prompt:

    Write a LinkedIn post about learning to code.

    Improve it in three steps:

  1. Add details: who is writing it, who will read it, and what message it should convey.
  2. Add format: length, number of paragraphs, whether to include hashtags, and how many.
  3. Run all three versions and compare which areas the model had to guess in each.

    Exercise 2: Try Each Prompt Style

    Write the same request in the four styles from this lesson. For example, to get a definition of "cloud hosting":

  • As a question
  • As an instruction with audience and length
  • As a completion using labels such as Term: and Simple definition:
  • As a conversational follow-up after first asking about web hosting in general Compare which style gave you the most control over the result.

    Exercise 3: Practice Specific Follow-Ups

    Ask a model to explain "what a database index is". Then write three follow-ups, each changing only one aspect of the answer: length, audience, and the type of example used. Check whether the model changed only what you asked.

0 Comments

Reviewed before they appear

No comments yet.

Prompt Engineering
Ask about this post
AI Ask about this post

Ask questions about Prompting Basics and get answers drawn from it.

Signed-in readers only.