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.
Use the figure to compare instruction refinement with context manipulation, examples, output control, recursive prompting, and chain-of-thought prompting. section 9.5
