Fundamentals

Prompt Engineering Basics

Fundamentals of prompting

What is a Prompt?

A prompt is a text instruction you send to a language model. The quality of the prompt directly affects the quality of the response. A good prompt clearly formulates the task, provides necessary context, and specifies the desired output format.

Specificity Principle

The more specific the prompt, the better the result. Instead of "write text" specify: topic, length, style, audience, format. The model can't read minds — everything important must be in the prompt.

Iterative Approach

It's rare to write a perfect prompt on the first try. Start with a simple version, evaluate the result, identify issues, and improve the prompt. Repeat until the result meets expectations.

Testing Prompts

Test prompts on different inputs. A prompt that works for one example may give poor results for others. Create a set of test cases and verify against them.

Interactive Demo

Iterative Prompt Improvement

Good prompts are created through iterations

Version 1

Write about dogs.

Quick Tips

Be specific
Write something
Write a 100-word summary of...
Provide context
Is this good?
Review this code for security issues: [code]
Specify format
List some ideas
List 5 ideas as bullet points, each under 20 words
Define the audience
Explain machine learning
Explain ML to a 10-year-old using everyday examples

Key Principles

  • Start simple, add complexity as needed
  • Test on different examples
  • Analyze errors and improve
  • Save prompts that work
  • Be specific about expectations
Common Mistakes
  • Too vague:"Help me with code"
  • No context:"What's wrong here?" (no code)
  • Contradicting instructions:"Be brief, but describe everything in detail"
  • Expecting mind reading:No requirements for format, style, length
Good Practices
  • Specify role:"You are an experienced Python developer..."
  • Provide context:"In the context of a React web application..."
  • Specify format:"Respond in bullet point format"
  • Give examples:"For example: input → output"
Basic Prompt Structure
[ROLE] — Who the model should be
You are a [role] with expertise in [domain].

[CONTEXT] — Background information
Context: [relevant information about the situation]

[TASK] — What needs to be done
Task: [clear task description]

[FORMAT] — How the response should look
Response format:
- [requirement 1]
- [requirement 2]

[CONSTRAINTS] — What to avoid
Constraints:
- Don't [constraint 1]
- Don't [constraint 2]

Try it yourself

Interactive demo of this technique

Technique Comparison
Demo Mode
Pre-recorded responses
TaskBeginnerWriting

Get a dinner recipe

Without technique
Without technique
Prompt
Recipe.
Response

Here is a pancake recipe:

Ingredients: flour, eggs, milk, sugar, salt, oil.

Mix ingredients, fry in a pan.

Tokens:3/30
Time:280ms
Quality:
With Prompt Basics
With technique
Prompt
Give me a dinner recipe for two. Cuisine: Italian. Time: under 30 minutes. Without: lactose. Format: ingredients (with grams) → steps (numbered).
Response

Pasta Aglio e Olio (2 servings, 20 min)

Ingredients:

  • Spaghetti — 200g
  • Garlic — 4 cloves
  • Olive oil — 60ml
  • Chili pepper — 1 pc
  • Parsley — 15g
  • Salt — to taste

Steps:

  1. Cook spaghetti al dente (8 min).
  2. Slice garlic thinly.
  3. Sauté garlic and chili in olive oil on low heat (3 min).
  4. Add spaghetti + 50ml pasta water. Toss (2 min).
  5. Garnish with parsley. Serve immediately.
👁️One word "Recipe" has no context — the model guesses what you want and picks the most common (pancakes)
🧠5 prompt parameters: who (two), what (dinner), style (Italian), constraints (lactose, 30 min), format (list + steps)
Basic prompt structure: task + context + constraints + format = predictable quality result
Tokens:32/120
Time:650ms
Quality:
Why this works

A one-word prompt is a lottery. Adding context (for whom), constraints (time, diet), and format (response structure), we get predictably useful results.

1 / 2

Lesson Quiz

1 of 3

1.Why is being specific and clear in prompts important for getting good results?

Practice Challenges

Create a free account to solve challenges

4 AI-verified challenges for this lesson

Related lessons:Prompt ElementsZero Shot

This lesson is part of a structured LLM course.

My Learning Path