liveBook · Manning

Prompt engineering

As explained in Generative AI in Action

Prompt engineering is the deliberate design and refinement of inputs provided to generative models to elicit desired outputs.

Prompt engineering is the deliberate design and refinement of inputs to a generative AI model to elicit a desired result. A prompt can contain text, images, or both, depending on the model. For an enterprise task, the aim is not merely to ask a question but to give the model enough direction to produce a useful response in the required form. section 6.1 section 6.1.1

A useful prompt can combine instructions, the content to process, input or output examples, cues, and supporting information. State the task clearly and specify the intended audience, format, or constraints where they matter. Put clear instructions before lengthy content: the order of information can change the result. section 6.2 section 6.8

Table 6.1 Elements that make up a prompt
Prompt element
Description
Instructions
The task you want the model to perform can also be a question.
Primary content
This is the main information we want the model to process and is typically used as part of the instructions.
Input examples
These are the details we want to get a response for. This can be a template or formatting rules to help the model understand.
Output examples
These specify the generation’s quality and whether a specific template is needed for the generation to follow.
Cue
These help add context, steer the model, and jumpstart the output. Typically, they are used before the instructions and the primary content.
Supporting content
At times, for more complex tasks, we can also have supporting content that acts as information and can influence the output. This content is different from the main content.

Use the prompt-elements table as a checklist when a response is vague or misses the required format; not every task needs every element. section 6.2

Turn a vague request into a business task

Instead of “Analyze sales data,” ask for “a concise report detailing the quarterly sales trends over the last two years, focusing on top-performing products.” The revised request supplies a time range, focus, and output form. For code documentation, splitting the request into purpose, parameters and types, and expected output makes each requirement explicit. section 6.2

Refine a prompt against the task rather than searching for one universal formula:

  • Try the prompt, inspect the generated response, and adjust instructions, content, examples, or cues. Record and evaluate results across iterations. section 6.2
  • Provide relevant examples when the model needs to infer a pattern. This is in-context prompting: it guides a response without retraining the model. section 6.3
  • Break complex requests into smaller tasks, constrain length or tone when useful, and supply an exit path such as “not found” when the answer is absent. section 6.8

Small edits can materially change a generation. Adding a question mark to “813 * 99” clarified the intended task in a GPT-3.5 example; adding “steampunk” to an image prompt changed its style. Neither result establishes a universal wording rule: test prompts with the model and task you will actually use. section 6.1.1

Prompting has limits. A model may struggle when its training does not fit the task; long prompts consume the context-window token budget, limit room for responses, and raise costs. Excessive direction can also make outputs echo the prompt. Review generated content rather than treating careful wording as a guarantee against errors or hallucinations. section 6.7 section 6.8

In production, manage prompts as application components: test and version them, monitor response quality, and coordinate them with evaluation and content moderation. Treat retrieved documents and user input as possible prompt-injection paths; clear delimiters and instructions help, but input and output checks, monitoring, and secure handling of secrets are also needed. Prompt engineering can be a starting point for an enterprise application, then work alongside retrieval-augmented generation or fine-tuning when requirements call for them. section 10.3.4 section 6.6 section 9.0

How Generative AI in Action covers it

How deep it goes
Develops prompt components, iterative refinement, examples, best practices, and operational risks without a mathematical derivation.
Examples
Uses revised sales-analysis and code-documentation requests, a GPT-3.5 arithmetic prompt, and contrasting image-style prompts.
What it assumes
Introduces prompts as natural-language task descriptions before treating their design as an iterative process.
What you can do after
Practice/perform iterative prompt design by evaluating responses and refining instructions, examples, and context.
How it connects
Connects in-context learning, PromptOps, prompt injection, retrieval-augmented generation, and fine-tuning to prompt design.

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 Generative AI in Action. The section links point to the parts of the book it draws on.