How to Do Automated Code Review with LLMs: Examples and Workflow

What is automated code review with LLMs

Automatedcode reviewCloudflare Clef-omniand domain specialists likeGLM-Legalis taking this technology to the next level, making code quality checks more thorough than ever.

Why LLMs are revolutionary for code review

Speed and context

  • LLMs understand natural language, code, and even spoken natural language thanks to models likeClef-omni, which handles text, images, audio, and video in a single pass.
  • They can analyze the entire pull request history, previous commits, and related documentation, providing context that traditional checks canโ€™t match.

Cross-language adaptability

With specialized models likeGLM-Legal(great for regulatory compliance) andFalcon-ASR(which excels at spoken Arabic text), you can apply domain-specific controls without needing multiple tools.

How to implement an LLM-based code review workflow

1. Choose the right LLM model

For most generic development use cases, an open-source LLM optimized for code (e.g., Qwen2-Coder or the latest multimodal models) is a solid starting point. For compliance checks, integrateGLM-Legalto ensure legal and compliance policies are respected.

2. Create an effective prompt

Well-structured prompts produce more reliable results. Hereโ€™s a ready-to-use prompt you can embed in GitHub Actions, GitLab CI, or any custom pipeline:

Analyze the following source code and provide:
1. Potential bugs or security issues.
2. Naming and formatting convention violations.
3. Suggestions for performance or readability improvements.

Return a structured summary with:
- Severity (High/Medium/Low)
- Location (file:line:column)
- Brief explanation
- Example recommended code

Code:def calculate_sum(lst):
    total = 0
    for i in lst:
        total += i
    return total

# Edge case: empty list
print(calculate_sum([]))

3. Integrate with your version control system

Use webhooks to trigger the LLM reviewer whenever a new commit is pushed or a pull request is created. Tools likeCloudflare Workerscan run Clef-omni models serverless, keeping costs proportional to the number of reviews.

4. Manage the results

Map LLM results to labels, issue comments, or CI tickets. A typical workflow is:

Practical example: from a pull request to detailed feedback

Imagine you have a PR that adds a new API for batch processing. By feeding the source code and the prompt above into a Clef-omni-based LLM service, you could receive output like:

=== Code Review ===

๐Ÿ’ผ Vuoi ottimizzare i tuoi processi con l'AI?

Scopri come possiamo aiutarti a creare prompt personalizzati e strategie AI su misura per il tuo business.

Richiedi Consulenza Gratuita