Prompt Engineering Techniques
Templates give you reusable structure. This lesson is about the text inside — audience, topic detail, and rules that keep the printed reply short and on point. We compare a vague ask with a clear one on the same HTML topic from Prompt Templates.
What it means here
Prompt engineering is not a separate library — it is how you write the strings you pass to invoke. Small additions (who the reader is, which tag to cover, how long the answer should be) often matter more than changing the model name.
Add a system line
SystemMessage sets the reader level and reply format before the question.
Write for Class 10 students. Keep each reply to one short sentence.
Be specific
Name the exact topic instead of a broad ask.
Explain the HTML <a> tag.
Set output rules
Length, format, and must-include facts keep the printed line on target.
Mention that it creates a hyperlink.
Keep temperature low
temperature=0 for study notes and repeatable demos.
ChatOpenAI(..., temperature=0)
Vague vs clear
Both calls below use the same ChatOpenAI setup with gpt-4o-mini and temperature=0. Only the message wording changes.
Vague
Tell me about the HTML <a> tag.
No role, no length limit, no required detail — reply may ramble or miss the key fact.
Clear
system
Write for Class 10 students. Keep each reply to one short sentence.
human
Explain the HTML <a> tag.
Rules: mention that it creates a hyperlink.
The demo script
prompt_engineering_demo.py prints two replies for the <a> tag so you can see the difference in your own terminal.
prompt_engineering_demo.py — included in the starter ZIP from Project Setup.Run it
python prompt_engineering_demo.pyChecklist before you invoke
| Question | If no, add it |
|---|---|
| Did I add a system line? | SystemMessage with reader level or format rules |
| Is the topic named clearly? | Exact tag, chapter, or task — not "tell me about HTML" |
| Did I set length or format? | One sentence, bullet list, table, etc. |
| Do I need a steady answer? | temperature=0 (see Model Parameters) |
Further reading: OpenAI prompt engineering guide.
What's Next
Clear system lines and rules change what prints. Next: wire steps together with LCEL.