liveBook · Manning

Prompt engineering

As explained in Software Testing with Generative AI

Prompt engineering is the deliberate design of inputs, instructions, constraints, and examples to influence a large language model toward a desired output.

Prompt engineering deliberately designs natural-language inputs, instructions, constraints, delimiters, and examples to increase the likelihood that a probabilistic large language model returns a useful, desired output. section 2.3 section 2.8

Build prompts around a specific task and make the expected result explicit:

  • Assign a useful role or perspective, such as an expert software tester, without treating the model as genuinely inhabiting that role. section 4.2
  • State constraints for scope, quality characteristics, numbering, length, and output structure; detailed instructions outperform broad questions. section 2.3 section 2.8
  • Use delimiters to separate rules and task data, then provide examples when format or context matters. section 2.8 section 6.1.1
  • Break complex work into subtasks and ask the model to check assumptions or evaluate its solution before returning it. section 2.4.6 section 2.8

From a broad request to a testable prompt

A weak request such as “Create tests for a file upload feature” invites generalized cases. A stronger version assigns a tester role, delimits the behavior, and requests exhaustive cases: “You are an expert software tester. Generate as many test cases as possible for the behavior delimited by three hashes. ### An Authorization API takes a token from another API and checks whether it is valid and in date before responding positively or negatively. ###” The resulting cases can target valid and expired tokens, but a human must still verify relevance, completeness, and factual correctness. section 10.1 section 2.2.3

% room_name | string | random
% type | string |  'single' or 'double'
% beds | integer | 1 to 6
% accessible | boolean | true or false
% image | string | random url
% description | string | random max 20 characters
% features | array[string] | 'Wifi', 'TV' or 'Safe'
% roomPrice |  integer | 100 to 200

A delimited schema demonstrates how to specify field names, data types, allowed values, and randomization rules when generating test data. section 6.1.1

Prompt engineering improves the odds of relevance, rule-following, and usable structure; it does not remove hallucinations, weak assumptions, inconsistent relationships, or privacy risks. Treat generated content as assistance requiring human judgment, and avoid sharing business or user information without authorization. section 2.2.3 section 6.1.1

How Software Testing with Generative AI covers it

How deep it goes
Explains prompt construction through constraints, delimiters, examples, decomposition, and evaluation, while stopping short of eliminating model errors.
Examples
Demonstrates Contact Us risk prompts, authorization API test cases, simulated rubber-duck feedback, and delimited room-data schemas.
What it assumes
Assumes a specific testing task and basic awareness of LLM behavior while teaching prompt construction from natural-language inputs.
What you can do after
Apply prompt tactics to formulate specific testing tasks and obtain more structured, context-relevant LLM assistance for human review.
How it connects
Connects large language models with hallucinations, data privacy, delimiters, test-case generation, and synthetic test data.

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