AI-generated code is source code produced by an AI assistant from a prompt or other supplied context. It can turn a small request into a working implementation quickly. That speed is useful for scaffolding and exploration, but it can also produce behavior nobody chose. A passing test shows that code works under the tested conditions; it does not establish that its business rules were requested. section 3.0 section 3.4.2
A plausible endpoint with an invented rule
An engineer asks an assistant to implement an order endpoint. The result returns 409 for cancelled orders, although nobody specified that behavior. The engineer accepts it, and a reviewer approves the reasonable-looking response. The team now owns a business rule that entered through the implementation rather than a decision. section 3.0
Listing 3.4 Abstraction-centric code
export class OrderService {
constructor(
private db: Database,
private cache: CacheService,
private validator: ValidationService
) {}
async validate(order: Order): Promise<ValidationResult> { /* ... */ }
async calculateTotals(order: Order): Promise<OrderTotals> {
const tax = subtotal * 0.10; // Invented 10% tax rate
// ...
}
async getById(id: string): Promise<Order | null> {
const cached = await this.cache.get(`order:${id}`);
// ...
}
}
The order-service listing makes the review problem concrete: a 10% tax rate and caching sit inside otherwise plausible structure. Ask where each choice came from before judging whether the code looks complete. section 3.3.2
Keep generation inside a visible decision process:
- For production behavior, give the prompt a specification or contract. State the intended outcome, not just an activity such as “add validation.” section 3.3 section 3.4.2
- Before review, make the generated code compile and pass existing tests. In the pull request, record the problem, decisions made, and choices deliberately left out. section 3.4.2
- Review the path from request to contract to implementation. Question extra status codes, validation, caching, dependencies, and abstractions instead of approving a polished diff on appearance alone. section 3.3.2
- Treat suggested bug fixes as hypotheses. Diagnose the cause before asking AI to write the fix. section 8.4
A fix that hides the failure
An intermittent database test prompts an AI-suggested retry loop. The test passes, but the helper still starts an asynchronous insert without awaiting it. Adding `await` addresses the race condition; retrying merely makes the symptom less visible. section 8.4
The practical test is ownership: can a developer explain why the code behaves this way, maintain it later, and remove what is unnecessary? Compare a handwritten and an AI-assisted version of the same small change for assumptions, review effort, and ease of modification—not just speed or line count. Human review restores accountability only when it establishes that understanding. section 3.5 section 13.1.1
