TracksPractical Coding FoundationsCoding With AI AgentsIterating With AI Feedback(4 of 8)

Iterating With AI Feedback

Getting great code from AI is usually a conversation, not a single question. The first response might be close but not quite right. Through iteration — asking follow-up questions and requesting changes — you refine the code until it meets your needs.

Building on Initial Responses

When AI gives you code that's almost right, don't start over. Build on what you have:

You: Write a function to calculate the average of a list

AI: [provides basic function]

You: Good, but handle the case where the list is empty

AI: [adds empty list check]

You: Also add type hints

AI: [adds type hints]

Each message improves the code incrementally. This is often faster and more effective than trying to specify everything in one massive prompt.

Common Follow-Up Requests

Here are useful ways to refine AI-generated code:

  • "That's close, but also handle negative numbers"
  • "Can you make this more efficient?"
  • "Add error handling for missing keys"
  • "Simplify this — it's more complex than needed"
  • "Add comments explaining the logic"
  • "Rewrite this using list comprehension"

Be specific about what you want changed. "Make it better" is vague. "Add input validation for empty strings" is actionable.

When to Keep Iterating

Continue refining when:

  • The code doesn't handle all your use cases
  • You don't understand part of the implementation
  • The code works but feels overly complex
  • You want to learn alternative approaches

When to Stop

Know when you've reached a good stopping point:

  • The code handles all your requirements
  • You understand how it works
  • Further changes would be minor style preferences
  • You're going in circles without improvement

If you've asked for the same thing multiple times and the AI keeps missing it, try rephrasing your request or providing a concrete example of what you want.

Learning Through Iteration

Iteration isn't just about getting working code — it's a learning opportunity. Ask the AI to explain why it made certain choices. Request alternative approaches. Use the conversation to deepen your understanding.

Think of AI iteration like sculpting. You start with a rough shape and refine it gradually until it matches your vision.

See More

You need to be signed in to leave a comment and join the discussion