AI and LLMs from zero
Prompting Well
- Week 6 of 12, AI and LLMs from zero
- You will learn a repeatable way to write and improve prompts.
Outcomes
What You Will Be Able To Do
- Write prompts with role, task, context, format
- Use examples to show a pattern
- Structure long prompts with labels
- Improve prompts through small tests
- Recognize and fix common failures
Mindset
Think Of A Capable New Colleague
- Reads fast and writes well
- Knows nothing about your situation
- Cannot see your goals or audience
- Weak output usually means missing information
Setup
Roles And Messages
- System message: tone, scope, limits
- Chat tools hide it; APIs expose it (week 10)
system: standing rules and role
user: the current request
assistant: the model's reply
Roles
A Role That Helps
- Role sets audience, style, and depth
- A role adds no new knowledge
Weak: You are an assistant.
Better: You are a patient tutor who explains
concepts to adult beginners using
everyday examples. Answer only from
the supplied text.Anatomy
Four Parts Of A Strong Prompt
- Task: a direct instruction
- Context: audience, purpose, facts
- Format: list, table, JSON, length
- Constraints: tone, scope, limits
| Part | Question it answers |
|---|
| Task | What exactly should be done? |
| Context | What does the model need to know? |
| Format | What should the answer look like? |
| Constraints | What to avoid or limit? |
Clarity
Say What You Want
- Positive targets are easier to follow
- Not: do not use jargon
- Better: write for a high school student
- Make it checkable: 3 bullets, under 20 words
Examples
Show, Do Not Only Tell
- Zero-shot: none. One-shot: one. Few-shot: several
Classify the review as positive or negative.
Review: The battery lasts all day.
Label: positive
Review: It broke after two days.
Label: negative
Review: Fast delivery but the screen is dim.
Label:
Technique
Reasoning Step By Step
- Chain-of-thought helps on multi-step tasks
- Some models reason on their own; test it
A shop sells pens at 3 for 2 dollars.
How much do 12 pens cost?
Think through the steps, then give the
answer on a last line starting with ANSWER:
Layout
Structure Long Prompts
- Labels or tags separate the parts
- Material first, question after it
<role> ... </role>
<rules> ... </rules>
<example> ... </example>
<document>
...pasted text...
</document>
Question: ...
Reply in the format: ...
Format
Asking For Structured Output
- Name the fields and allowed types
- Say nothing else should be returned
- Validate the result in code
Return only JSON with these keys:
{"title": string, "actions": [string],
"deadline": string or null}Method
Iterate Like An Engineer
- Run on several real inputs
- Find the pattern in the errors
- Change one thing at a time
- Rerun the whole set and compare
Troubleshooting
Failure Patterns And Fixes
- Vague output: add audience, length, format
- Invented facts: supply the source, answer only from it
- Ignored rule: shorten, state once, place near end
- Wrong format: show an exact sample
- Too agreeable: ask for flaws and counterarguments
| Problem | Fix |
|---|
| Vague answer | State task, audience, length |
| Wrong format | Show an example of the format |
| Invented facts | Supply source text, allow 'I don't know' |
| Long prompt ignored | Use labeled sections, put the question last |
Fix for invented facts
Grounding The Answer
- Supply the facts yourself
- Allow the model to say it does not know
- Ask for the supporting quote
Answer using only the text in <document>.
If the answer is not in the text, reply:
"Not stated in the document."
Quote the sentence you used.
Limits
Where Prompting Stops
- No wording can supply facts the model never saw
- Large document sets exceed the context window
- Some tasks need actions, not only text
- Retrieval and tools fill these gaps
Summary
Recap
- Be clear: task, context, format, constraints
- Show examples and structure long prompts
- Iterate on a small test set
- Know the failure patterns and their fixes
Next week
Next Week: RAG And Tools
- Retrieval-augmented generation: find the right text first
- Embeddings and search from week 4 put to work
- Preview of tools that let a model take actions
Wrap up
Questions And Exercise
- Exercise: Improve a prompt on a test set
- Share one result at the next session
- Bring one question to week 7