liveBook · Manning

Prompt engineering

As explained in How Large Language Models Work

Prompt engineering is the practice of designing and modifying input text to influence a language model's behavior or output.

Prompt engineering is the practice of designing and modifying input text to influence a language model’s behavior. A prompt constrains the task by specifying goals, detail, tone, or output format, much like giving a computer precise plain-language instructions. section 5.1

Prompt engineering can support several practical uses:

  • Ask for structured outputs, such as comma-separated values for copying into Excel. section 5.1
  • Summarize free-form survey responses into themes or roleplay a car salesperson. section 5.1
  • Rewrite a user’s question before searching to potentially improve retrieval results. section 5.5.1
  • Treat prompt changes as experiments rather than guarantees: updates to a model can make previously useful prompts stop working. section 5.5.1

Adding instructions around retrieved information

A retrieval-augmented generation workflow can place “Answer the question:” before a question and “Using the following information:” before retrieved documents. Extra instructions may improve relevance, but the result still depends on the model and prompt wording. section 5.5.1

Figure 5.11 On the left, we show the normal use of an LLM of a user asking about how to write JSON. LLMs naturally have the chance of producing errant outputs, which we want to minimize. On the right, we show the RAG approach. By using a search engine, we can find documents that are relevant to a query and combine them into a new prompt, giving the LLM more information and context to produce a better answer.
figure

Compare ordinary prompting with retrieval-augmented generation: retrieved documents add information and context intended to reduce errant outputs. section 5.5.1

How How Large Language Models Work covers it

How deep it goes
Defines prompts, demonstrates modifications, and explains brittleness, while stopping short of a procedural optimization method.
Examples
Uses car-selling bots, CSV formatting, survey-theme summarization, and question rewriting for search.
What it assumes
Relies on understanding that standard LLMs generate continuations and that fine-tuning changes their objectives for instruction following.
What you can do after
Apply explicit prompts to repetitive, fuzzy tasks while testing results rather than treating fluent output as guaranteed accuracy.
How it connects
Connects prompting to retrieval-augmented generation, fine-tuning, information retrieval, and query expansion.

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 How Large Language Models Work. The section links point to the parts of the book it draws on.