Skip to contentSkip to main content
Get Useful Answers from AI — a free microcourse with a reusable templateStart learning
TechlyUp
Core AI skills

How to review AI-generated code before merging it

By TechlyUpUpdated 2 min readDevelopers

Quick answer

Review AI-generated code like any other untrusted contribution: understand the intended behavior, inspect the complete diff, test normal and boundary cases, and check security and dependency changes. Use AI feedback as additional input while keeping a human responsible for the merge.

Write the behavior before requesting code

Give the assistant the repository instructions and the relevant files, then describe the smallest change. State what should happen for invalid input as well as normal input. This makes it easier to detect a polished implementation of the wrong requirement.

For this synthetic JavaScript exercise, convert a non-negative integer number of minutes into hours and remaining minutes. Negative values, fractions, and non-numbers must be rejected. We deliberately keep the exercise independent of a changing framework API.

Use a small, inspectable implementation

This example is practice code, not a production library. Run the accompanying checks and add cases appropriate to your own application.

export function splitMinutes(value) {
  if (!Number.isSafeInteger(value) || value < 0) {
    throw new TypeError("Expected a non-negative safe integer");
  }
  return { hours: Math.floor(value / 60), minutes: value % 60 };
}

Test the contract and the boundaries

For 0, expect { hours: 0, minutes: 0 }. For 59, expect { hours: 0, minutes: 59 }. For 60, expect { hours: 1, minutes: 0 }. For 125, expect { hours: 2, minutes: 5 }. Inputs -1, 1.5, "60", NaN and Infinity must throw.

Notice that accepting the string "60" by coercion would fail our contract even if the result looked reasonable. Tests should follow the agreed behavior, not copy assumptions made by the generated implementation.

Review more than the happy path

Inspect every changed file, including lockfiles and configuration. Look for unrelated edits, hidden network requests, logs containing sensitive values, new permissions and unnecessary dependencies. In a real app, also review authorization and failure behavior relevant to the change.

Use the repository’s required checks. Summarize the behavior changed, tests run and remaining limitations in the pull request. A second AI review can help find issues but is not proof of correctness.

Try it yourself

Save the function in a local practice file. Write assertions for the four valid cases and rejection checks for the five invalid cases above. Change one line deliberately and confirm a relevant test fails before restoring the implementation.

Want a suggested next step for your situation?

Share a few details and someone from TechlyUp will get back to you. No automated sequences.

Sources and further reading

Examples are authored practice material, not measured learner outcomes. Tool behavior can change. Found an error? Contact TechlyUp with the page URL and correction.

Continue learning

Core AI skills2 minProfessionals and beginners

How to write better AI prompts for work

Use task, context, format, and constraints to turn a vague workplace question into a prompt you can check and reuse.

Read guide

Core AI skills2 minProfessionals and beginners

How to check an AI answer before using it

A practical verification checklist for facts, calculations, citations, and missing information in AI-generated work.

Read guide