liveBook · Manning

Recursive prompting

As explained in Coding with AI

Recursive prompting is a prompting technique that repeatedly uses prior outputs or intermediate results to generate subsequent prompts or responses.

Recursive prompting improves an AI-generated answer through repeated stages instead of accepting the first response. Each output becomes input for analysis, correction, or further refinement. section 9.5.2

Use the technique as a deliberate refinement cycle:

  • Start with a prompt requesting a solution or response. section 9.5.2
  • Inspect the initial output for omissions, edge cases, or errors. section 9.5.2
  • Feed the result back with a more specific request for correction or improvement. section 9.5.2
  • Repeat until the result meets the required quality and accuracy. section 9.5.2

Refining a Python factorial function

Begin with “Write a Python function to calculate the factorial of a number.” Then request handling for negative numbers and non-integer inputs. Finally, ask for an iterative implementation instead of recursion. The successive versions add validation and replace recursive calculation with a loop. section 9.5.2

How Coding with AI covers it

How deep it goes
Explains the cycle through initial prompting, critique, recursive input, and repetition, stopping short of formal model internals.
Examples
Demonstrates factorial code by adding input validation and then changing recursive calculation to iteration.
What it assumes
Assumes programming fundamentals sufficient to inspect generated code and judge requested corrections.
What you can do after
Apply it to refine generated code by identifying omissions, requesting targeted changes, and repeating validation.
How it connects
Connects recursive prompting with chain-of-thought, context manipulation, instruction refinement, and output control.

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.