liveBook · Manning

Prompt engineering

As explained in Learn AI-Assisted Python Programming, Second Edition

The practice of designing and refining instructions for an AI system to improve the relevance and correctness of its outputs.

Prompt engineering is the practice of designing and refining instructions for an AI coding assistant. Clear English requests help Copilot produce more relevant code, but precision cannot guarantee correctness: even a careful prompt may produce a mistake. section 1.6 section 3.8

Use an iterative prompt-and-check routine:

  • Describe the required task precisely, including the function’s purpose, parameters, and expected result. section 1.6 section 3.8
  • Inspect and test the generated code rather than assuming that fluent-looking code is correct. section 1.6 section 6.0
  • When the result is wrong or incomplete, identify the problem and revise the prompt; small wording changes can substantially change the output. section 1.6 section 8.3.2
  • Test with varied inputs and keep debugging under your own control, so you can judge whether suggested fixes and tests are reasonable. section 3.8 section 6.0

Requesting a more useful explanation

If a general explanation is too vague, replace it with a specific request: “Explain that code again, but do it line by line. Give each line of code and the explanation of what it does.” The revised prompt asks for the level of detail needed to connect each statement with its purpose. section 4.2

/explain

Use the /explain command as a starting point, then craft a more specific prompt when the built-in explanation does not meet your needs. section 4.2

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Explains precision, testing, and prompt revision procedurally, while deferring detailed prompt patterns beyond function requests and explanation requests.
Examples
Uses function headers, docstrings, rewritten function prompts, /explain, and line-by-line explanation requests.
What it assumes
Assumes basic programming tasks and teaches precision, testing, debugging, and independent verification as essential companion skills.
What you can do after
Diagnose/debug with it by testing Copilot output, identifying errors, and revising prompts to seek better code or explanations.
How it connects
Connects prompt engineering with debugging, testing, functions, unit testing, and problem decomposition.

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 Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.