liveBook · Manning

Instruction refinement

As explained in Coding with AI

Instruction refinement is the systematic process of making AI instructions clearer, more specific, and less ambiguous to improve the usefulness and predictability of generated outputs.

Instruction refinement makes AI directions clearer, more specific, and less ambiguous so generated code or documentation becomes more accurate, useful, and predictable. It is especially effective for Python programming and other structured development tasks, but its emphasis on narrowly constrained results makes it unsuitable for highly creative work. section 9.5.4

Refine a complex request by:

  • Defining a clear objective for what the code should accomplish. section 9.5.4
  • Breaking complex requirements into bite-sized, actionable steps. section 9.5.4
  • Specifying constraints, preferred methods, and relevant background context. section 9.5.4
  • Defining the expected output format when the result must follow a known structure. section 9.5.4

Processing JSON data

A vague request to process JSON can be refined into a Python task that reads a file, validates records, saves them to a database, handles errors, and returns a success flag with a processed-record count. The resulting code example uses json, logging, typing, SQLAlchemy, a documented function signature, and explicit database-session setup. Generated code still requires deliberate review and validation before use. section 9.5.4

Figure 9.5 For advanced prompts, you’ll need to provide a lot more information. You need to manipulate context and examples, refine your instruction, and dictate the output. You can also use recursive and chain-of-thought prompting to get the model to think about the answers.
A diagram of a company

Description automatically generated

Use the figure to compare instruction refinement with context manipulation, examples, output control, recursive prompting, and chain-of-thought prompting. section 9.5

How Coding with AI covers it

How deep it goes
Explains a five-step refinement process and its trade-off, stopping short of detailed model internals.
Examples
Demonstrates JSON processing with validation, database persistence, error handling, logging, typing, and SQLAlchemy session setup.
What it assumes
Assumes software-development tasks and basic interaction with AI assistants while teaching the refinement sequence explicitly.
What you can do after
Apply instruction refinement to produce more constrained and useful AI-generated Python code or technical documentation.
How it connects
Connects clear instructions with prompt engineering, context manipulation, output control, recursive prompting, and chain-of-thought prompting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.