Appendix: Prompting Patterns
This section collects reusable patterns - short recipes for common tasks. They're organized by complexity.
Single-shot patterns
These patterns use a single API call with no conversation history.
Summarization
"Summarization" is a machine learning problem where you take a piece of text and shrink it.
The following is called a "zero-shot summarizer." It is called zero-shot because we don't provide an example output to the AI.
Until around 2020, this used to be a very difficult problem that required machine learning experts, training data, and specialized models.
And then LLMs came along.
No machine learning required. Just a simple API call.
async function summarizer(text) {
const botResponse = await sendPost("https://acme-ai.com/v1/chat", {
sender: "user",
message: `
${text}
Please summarize the above text in simple language, in 1 paragraph of about 100 words.
`
})
return botResponse.message;
}
Classification
"Classification" is a machine learning problem where you input text and get back a label.
Similar to summarization, classification also used to require machine learning expertise, data samples, and formal evaluations.
Now, using LLMs, anybody can build a classifier in no time.
async function classifier(ticket) {
const botResponse = await sendPost("https://acme-ai.com/v1/chat", {
sender: "user",
message: `
${ticket}
classify the above ticket. return a single word chosen from the following labels: feature, bug, research, support, architecture
`
})
return botResponse.message;
}
Translation
A transformation takes information in one format and rewrites it to another.
The traditional machine learning technique used for this is "sequence-to-sequence learning."
This can be used for translation, simplification, and data conversion.
async function translateToCanadianFrench(englishInput) {
const botResponse = await sendPost("https://acme-ai.com/v1/chat", {
sender: "user",
message: `
${englishInput}
translate the above text to Canadian French.
`
})
return botResponse.message;
}
Multi-turn patterns
Coming soon.
Agentic patterns
Coming soon.