Code Review for a System Integrating AI Models
A code review focused on failure modes unique to LLM integration: unexpected output handling, timeouts, cost, prompt injection, and data leakage.
Prompt
Review the following code, which integrates a language model. Focus on LLM-specific failure modes that ordinary code review misses.
Code: <code> [Paste] </code>
Context: [what the code does and what happens to the output]
Check in this order:
- Unexpected output — what happens when the model returns malformed JSON, a missing field, a wrong type, or prose before the JSON? Is there validation before use, or will a direct parse crash the flow?
- Network failures — is a timeout set? Retry with backoff? What happens on a 429 or 503? Would a retry on a partially completed action cause duplication?
- Cost and budget — is there an input token limit? What stops a loop that calls the model unbounded? Is cost measured?
- Prompt injection — does user input enter the prompt without delimitation? Can retrieved document content contain instructions the model will follow?
- Data leakage — what is sent to the external provider? Can secrets, keys, or client data enter the prompt? Are prompts logged with their content?
- Non-determinism — does the code assume a fixed format the model may break? Is temperature appropriate for the task?
- Failure experience — when the model fails, what does the user see? Does the system fabricate an answer instead of admitting failure?
For each finding: severity (blocker / important / improvement), a short explanation, and the fix as a code snippet. Do not report style issues.
Why this converts well
- Ready to copy and use immediately
- Tailored for legal and public-sector work
- Easy to adapt to internal workflows
Tags
Related Prompts
Tool Specification for a Legal AI Agent
Produces a complete agent tool definition — schema, description, errors, permissions — with emphasis on tools that perform irreversible actions.
Designing a Structured Output Schema for Legal Data
Designs a JSON schema for legal data extraction with explicit representation of uncertainty and missing values instead of silent defaults.
Regression Test Suite for a Production Prompt
Builds a test suite for a prompt before changing it, catching silent regressions introduced by an innocent-looking improvement or a model swap.