liveBook · Manning

Prompt

As explained in The Quick Python Book, Fourth Edition

A prompt is an instruction or input supplied to an AI system to elicit a particular response or generated output.

A prompt is the input given to an AI code generator to describe the code you want. A useful prompt states the task, identifies the data and names any requirements that matter. Generated code can save time, but it still needs to be read, run and checked. section 2.5 section 5.9.2

Before entering a prompt:

  • Work out what the program must do. Solving the problem yourself first can make the request more precise and the result easier to evaluate. section 5.9.1
  • Include the required operations, inputs and outputs, but omit work already done. If a list of temperatures has been loaded, ask for the calculations rather than another file reader. section 5.9.3
  • Specify constraints that could change the solution. For a word-counting task, ask for a dictionary if using a dictionary matters; otherwise the generator may use Counter. section 7.8.1
  • When changing existing code, make that code available and describe the intended change. A request to restructure processing into functions needs the working code and that structural goal. section 9.9.1

Ask for exactly the missing work

Suppose Python has already read temperatures into a list. Ask: “Using the list temperatures, find the high, low, mean, and median temperatures, and show how many unique temperatures are in the list.” The request names the available input and every desired result without repeating the file-loading step. section 5.9.3

Using the list temperatures, find the high, low, mean, and median 
temperatures, and show how many unique temperatures are in the list.

The complete temperature prompt is short enough to inspect against its required outputs. section 5.9.3

The amount of detail depends on the task. A text-cleaning request can name the source and output files and spell out lowercase conversion, punctuation removal and word splitting. A command-line refactoring request can specify the behavior to imitate, the supported options and the expected form of the output. In either case, provide the generator with any existing code it must change. section 6.10.1 section 11.5.1

Treat the generated program as a candidate solution, not a verified answer. In one weather-file task, a generator checked whether 'Cook' was an entire field in a row rather than checking the county field; the resulting CSV contained only its header. Run the code, inspect its output and refine the request or fix the code when it misses the requirement. section 21.6.2 section 5.9.2

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Develops a practical checklist of requirements, context and constraints, then tests generated results; does not explain generator internals.
Examples
Shows requests for temperature statistics, text cleaning, word counts, wc-style options and weather-data extraction.
What it assumes
Assumes enough understanding of the programming problem and Python to specify requirements and judge the generated solution.
What you can do after
Practice/perform prompt writing for AI code generators, then run and evaluate the generated Python code.
How it connects
Connects prompts to AI code generation, Python functions, dictionaries, file processing and command-line programs.

Also explained in

Compare how 50 books explain prompt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.