liveBook · Manning

Prompt engineering

As explained in Data Analysis with LLMs

Prompt engineering is the systematic design and search of prompts or prompt templates to guide a language model toward better task results.

Prompt engineering is the systematic design and search of prompts or prompt templates that guide a language model toward better task results. A strong template states the task clearly and supplies relevant context. section 1.5.3 section 9.5

Use prompt engineering to improve results by:

  • Defining the requested task and the required answer format explicitly. section 1.5.3
  • Testing alternative templates rather than assuming the first wording is best. section 1.5.3 section 9.5
  • Adding a few labeled examples when the task is difficult to communicate through instructions alone. section 9.5
  • Improving the performance of cheaper models when an optimized template is sufficient for the task. section 1.5.3

Few-shot sentiment classification

A classification prompt can show a review, its label, and then a new review to classify. For example: "[Sample Review] Is the sentiment positive or negative? Answer (\"pos\"/\"neg\"): [Sample Solution] [Review to Classify] Is the sentiment positive or negative? Answer (\"pos\"/\"neg\"):". Repeating this structure with labeled samples helps specify both the task and the expected output. section 9.5

[Sample Review]
Is the sentiment positive or negative?
Answer ("pos"/"neg"):[Sample Solution]
[Review to Classify]
Is the sentiment positive or negative?
Answer ("pos"/"neg"):

Inspect the compact sample-review template to see how an example, reference answer, target input, and constrained output format fit together. section 9.5

How Data Analysis with LLMs covers it

How deep it goes
Explains task specification, contextual prompting, template experimentation, and few-shot examples without detailing model internals.
Examples
Uses sentiment classification, labeled reviews, constrained positive-or-negative answers, and alternative prompt templates.
What it assumes
Assumes only a language-model task and teaches prompting through explicit instructions, context, examples, and output formats.
What you can do after
Build it from scratch by designing and testing prompt templates for familiar or novel language-model tasks.
How it connects
Connects prompting with few-shot learning, model selection, tuning parameters, and fine-tuning.

Also explained in

Compare how 38 books explain prompt engineering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Analysis with LLMs. The section links point to the parts of the book it draws on.