Prompt Engineering for Language Models

Prompt engineering - keyboard and chat

What is Prompt Engineering?

Prompt engineering is the art and science of phrasing requests to AI tools so they produce the best results. It's a critical skill in the AI age – how you ask directly affects the quality of the answer.

Think of it like ordering food: "Bring me something tasty" will get a very different result from "I want pasta in tomato sauce, no onion, with grated cheese on the side".

In this lesson we'll use the CRAFT model – a simple five-letter framework for building effective prompts, plus principles and techniques for better results.

💡 Why it matters:

The same AI can give a mediocre or excellent answer – depending on how you asked. Learning prompt engineering is the best investment for using AI effectively.

🎯 Core principle: clarity and planning

Before you type a question to the AI, pause and think. These questions match the CRAFT components – use them as a quick check:

  • What exactly do I want? – Short answer? Long? List? Table?
  • Who is the audience? – Experts? Beginners? Children?
  • What style? – Formal? Friendly? Technical?
  • What's the context? – Why do I need this?
  • What do I not want? – Anything to avoid?

❌ Vague prompt

"Tell me about Python"

Problem: Unclear if you mean the programming language or the snake. Even then – what exactly do you want to know?

✅ Clear prompt

"Explain the programming language Python in 5 main points, at a level for a complete beginner. Focus on advantages and common uses."

Advantage: Clear what you want, how much, for whom, and the focus.

The CRAFT model – building a good prompt

CRAFT is a simple framework: five letters that cover what to think about before writing a prompt. You don't have to use all five every time – even 3–4 elements improve results a lot.

  • C – Context: Give background and situation. Why do you need this? In what field? What limits or conditions?
  • R – Role: Assign the model a role or expertise. E.g. "You are a math teacher with 15 years of experience" or "Act as a copy editor".
  • A – Action: State clearly what you want done. A clear, concrete task – not "help me" but "Write three paragraphs about…" or "Prepare a list of…".
  • F – Format: Say how you want the answer: list, table, paragraphs, bullet points, code, two-sentence summary.
  • T – Tone: Set style and voice – formal, friendly, technical, simple for kids.
💡 Short CRAFT example

"Context: I'm preparing a talk for 8th graders. Role: Act as a science teacher explaining to kids. Request: Explain what DNA is in three simple sentences. Format: Three short paragraphs. Tone: Friendly and clear, no heavy jargon."

📋 7 golden principles

After filling in CRAFT, these principles help sharpen your prompt and improve results:

1

Be specific

The more precise you are, the more relevant the answer. Instead of "help me write an email", write "Help me write a professional email asking for a raise, respectful but assertive, 150–200 words."

2

Provide context

Give relevant background. "I'm a 4th grade teacher" or "I'm a developer with 5 years of experience" – it changes the answer completely.

3

Define format

Say how you want the answer: numbered list, table, short paragraphs, bullet points, code with comments.

4

Give examples

If you have an example of what you want – share it. "Write in the style of this example…" helps the AI understand exactly what you want.

5

Set a role

Ask the AI to play a role: "Act like a physics teacher", "Imagine you're a lawyer", "Answer as a marketing expert".

6

Limit the answer

Specify length, number of points, or scope: "In 3 sentences", "Up to 500 words", "Only 5 ideas".

7

Iterate

Don't settle for the first answer. Ask "Expand on the second point", "Give another example", or "Put this in simpler words".

🔧 Advanced techniques

1. Chain of Thought

Ask the AI to explain its reasoning step by step. This improves accuracy on complex problems.

Example:

"Solve the following step by step and explain the logic at each step: If Danny has 3 apples and Ronit has twice as many, and they gave half to Mom…"

2. Few-Shot Learning

Give 2–3 examples of what you want, then ask for more in the same style.

3. Role Playing

Ask the AI to adopt a specific persona for the whole conversation.

4. Constraints

Define what is and isn’t allowed.

📝 The perfect prompt structure – CRAFT template

Use this template to organize CRAFT for almost any topic:

[Role] - You are [expert/role]
[Context] - I am [who/situation]
[Action] - I need you to [exactly what to do]
[Format] - Present as [list/table/paragraphs]
[Tone] - Important that [style, conditions, what to avoid]

❌ Common mistakes to avoid

1. Prompt too short

❌ "Write an email" → ✅ "Write a professional email inviting a supplier to a meeting, friendly but businesslike, with 2–3 possible dates"

2. Assuming the AI knows context

❌ "What do you think of my idea?" → ✅ "My idea is to open an online store selling homemade cookies. What are the pros and cons?"

3. Closed questions when you want detail

❌ "Is Python a good language?" → ✅ "What are the pros and cons of Python vs JavaScript for backend?"

4. Not asking for fixes

✅ "That’s not quite what I meant. I’m looking for something more [what’s missing]. Can you try again?"

5. Asking everything at once

✅ Start with one topic and go deeper step by step.

💬 Practical examples by area

📧 Emails:

"Write a professional email to a customer complaining about a late delivery. Tone: empathetic and apologetic but also reassuring, with a proposed solution. Length: 100–150 words. Include: apology, brief explanation, proposed solution, and offer to compensate."

📚 Learning:

"Explain Einstein’s theory of relativity as if I'm 12. Use analogies from everyday life. Start from the most basic idea and build up. Length: 3 paragraphs."

💼 Work:

"I need to present a project to senior managers. Help me create a structure for a 10-minute presentation on launching a new product. Include: strong opening, 3–4 main points, closing with a call to action."

💻 Code:

"Write a Python function that takes a list of numbers and returns all the even ones. Include: documented code, usage example, and a short explanation of the logic."

🔄 Conversation is a process

Remember: a conversation with AI isn’t one question and one answer. It’s a dialogue you can refine. Evaluate the answer, ask for specific improvements ("expand on…", "shorten…", "add an example for…"), and iterate.

💡 If the answer isn’t good – it’s usually not "the AI’s fault". Try rephrasing with more detail or context, or run through CRAFT: Did you give Context (C), Role (R), clear Action (A), Format (F), and Tone (T)?

⚠️ Always remember

Important:
  • Verify facts: AI can be wrong or invent information. Always double-check important facts.
  • Don’t share sensitive data: Passwords, ID numbers, financial details – never.
  • Use judgment: AI is a tool, not a replacement for your own thinking.

Summary 📝

  • CRAFT: Context (C), Role (R), Action (A), Format (F), Tone (T)
  • Plan before you write; be specific; give context; define format; give examples when you can; iterate; verify the result.

📝 Test yourself

Answer 11 questions on prompt engineering and the CRAFT model.

1 What is prompt engineering?

2 What’s wrong with the prompt "Tell me about Python"?

3 What should a good prompt include?

4 What does the CRAFT model provide?

5 What is "Chain of Thought"?

6 Why give examples in a prompt?

7 What’s wrong with asking "Is Python a good language?"?

8 What does "set a role" mean in a prompt?

9 What to do if the AI’s answer isn’t accurate?

10 What should you not share with AI?

11 What is the most important principle in prompt engineering?

Your results

0/11Correct answers
0%Success rate

→ 5. Practical Tools 7. AI Ethics – Next ←