AI Engineering Notes: Prompt Engineering (Ch.5)

These are my personal summaries and observations from reading AI Engineering by Chip Huyen. They are not a comprehensive review — just the notes and takeaways that stood out to me. I highly recommend picking up the book for the full picture.


This chapter dives deep into prompt engineering — the techniques, best practices, and the security considerations that come with it.

Discussion topic: Is Prompt Engineering an art or a science? Some people may argue it is similar to reading the tea leaves — you can find what works but can never explain it.

Prompt Engineering Fundamentals

Best Practices for Prompt Engineering

Development Setup

# prompts.py
ENTITY_EXTRACTION_PROMPT = "..."
# app.py
from prompts import ENTITY_EXTRACTION_PROMPT

Techniques

Write clear and explicit instructions:

Ask the model to adopt a persona:

Specify output format:

Provide examples (few-shot prompting):

A photo from the book showing few-shot prompting: a prompt asks to label items as edible or inedible with examples (pineapple pizza = edible, cardboard = inedible, chicken = ?). The model output shows "edible".

Use markers to mark the end of the prompts.

Provide sufficient context for the model to understand:

Break complex tasks into simpler tasks:

Prompt the model to outline the reasoning and self-critique:

Screenshot of Gemini 2.5-Pro thinking steps showing a query about what time to leave from Sunnyvale to arrive in Las Vegas by 4pm, with thinking steps like Calculate the Route, Determining Departure Time, and Assessing Driving Time.

Screenshot of Gemini 2.5-Pro response showing Estimated Driving Time and Factoring in Stops and Potential Delays with bullet points about rest stops, meals, fuel, traffic, and unexpected delays.

How to Jailbreak Prompt Engineering

Why is Defensive Prompt Engineering Important?

How Are People Jailbreaking Models?

Discussion topic: Are we at an inflection point where AI Security will be a new rising industry as AI usage becomes mainstream?

Automated Attacks

Information Extraction

Red-Teaming

There are benchmarks that can help you evaluate safety of the model.

Key Metrics

Three Levels of Defense

Model-level defense:

Prompt-level defense:

System-level defense:

Discussion topic: Which level of defense is the most important and why?