Built to order

AI Code Review Assistant for Python Code Quality

This project builds an AI code review assistant that reads Python source files and flags bugs, security risks and maintainability issues before they reach production. It combines a CodeBERT model fine-tuned on CodeSearchNet Python pairs with a deterministic AST-based static checker, so every finding comes with a plain-language explanation and a suggested fix. A web demo lets you paste code and watch the review happen live, with findings grouped by severity and category. Suitable for B.E./B.Tech final-year projects in Computer Science, IT and AI & Machine Learning.

AI Code Review Assistant for Python Code Quality — project thumbnail preview
More project photos (2)

The problem

Code review is where most software defects are caught, yet in student and small-team projects it is often skipped or done superficially — reviewers skim for style while real bugs slip through. Commercial AI reviewers exist but are black boxes, and their training data and rules are hidden. This project builds the review pipeline in the open: Python code is parsed into an abstract syntax tree for exact structural checks (mutable default arguments, bare except clauses, SQL string concatenation, unused imports, deep nesting), while a CodeBERT model fine-tuned on CodeSearchNet suggests missing docstrings and summaries for undocumented functions. Because both layers are visible, the student can explain exactly how each finding is produced — a strong position for a viva. The web demo makes the pipeline tangible: paste any Python function and get an instant, categorized review with fix suggestions.

How it works

  1. Pasted Python source is parsed with the standard ast module into a syntax tree; syntax errors are reported immediately with line numbers.
  2. A set of AST visitor rules walks the tree and records matches — for example, a FunctionDef whose defaults contain a List or Dict node triggers the mutable-default-argument rule.
  3. Security patterns are matched against call sites: string-formatted SQL in execute() calls, os.system with f-strings, and hardcoded credential assignments.
  4. Undocumented public functions are passed to the fine-tuned CodeBERT model, which generates a draft docstring shown alongside the "missing documentation" finding.
  5. Findings are scored by severity, deduplicated, and sorted; the demo renders them with category filters (Bugs, Security, Style, Documentation).
  6. The summary panel aggregates counts by severity and category, and every finding links to a suggested fix snippet the student can copy.

Tech stack:

  • Python 3.11, ast module (static analysis core)
  • Hugging Face Transformers, CodeBERT (microsoft/codebert-base)
  • CodeSearchNet Python subset (training data)
  • PyTorch (fine-tuning)
  • Flask (demo backend) + HTML/CSS/JS (demo frontend)
  • pytest (rule test suite)

Dataset & model details

  • Dataset: CodeSearchNet (Husain et al., 2019) — 2M+ (function, documentation) pairs mined from open-source GitHub repositories across 6 languages; the Python subset (~457k pairs) is used for fine-tuning. Source: github.com/github/CodeSearchNet.
  • Task: Code-to-text generation (draft a docstring/comment for a given Python function) plus AST-based defect detection as the deterministic layer.
  • Model: CodeBERT (microsoft/codebert-base, 125M parameters) fine-tuned on CodeSearchNet Python pairs for comment generation; static rules implemented as ast.NodeVisitor subclasses.
  • Metrics: BLEU score on a held-out CodeSearchNet Python split for comment generation (design target, not a claimed result); per-rule precision/recall measured on the shipped labeled test suite and reported honestly in the report.
Parameter Value
Input Python 3 source, single file or pasted snippet
Static rules 18 AST/security checks (documented list)
Model CodeBERT-base fine-tune, ~125M parameters (design target)
Comment BLEU Design target on held-out split (reported after training)
Demo latency Under 2 s for a 500-line file on CPU (expected)
Demo Single-file web app, runs offline after download
Fine-tuning Approximately 2–4 h on a single GPU (expected)

Project features

  • [AST-based static checks] Deterministic analysis over the Python abstract syntax tree catches structural bugs — mutable default arguments, bare except:, eval() usage, unused imports and variables, and functions with excessive complexity.
  • [CodeBERT comment generation] A CodeBERT model fine-tuned on CodeSearchNet Python pairs drafts docstrings for undocumented functions, demonstrating transformer-based code understanding.
  • [Security-focused rules] Flags SQL string concatenation, hardcoded credentials, pickle.loads on untrusted data and shell injection patterns, each with a plain-language risk explanation.
  • [Severity-ranked findings] Every issue is scored and grouped as Critical, Warning or Suggestion, so the most dangerous problems surface first.
  • [Fix suggestions] Each finding ships with a concrete corrected code snippet, not just a complaint — the demo shows before/after for every rule.
  • [Live web demo] Paste Python code and get an instant review in the browser: findings list, severity filters, per-rule explanations and an issue summary panel.
  • [Rule test suite] Each checker ships with positive and negative test cases, so the report documents exactly what the tool catches and what it misses.

What is included

  • AST-based static checker source code (18 documented rules)
  • Fine-tuned CodeBERT adapter weights for docstring generation
  • Training notebook (CodeSearchNet loading, fine-tuning, BLEU evaluation)
  • Live web demo wired to the checker and model
  • Per-rule test suite with positive/negative cases
  • Project report PDF (background, transformer code models, rule design, methodology, results)
  • PPT presentation for final review
  • Viva Q&A preparation document (ASTs, CodeBERT, BLEU, static vs dynamic analysis)

Limitations & prerequisites

  • Static rules are pattern-based and can miss novel bug shapes; they complement, not replace, human review.
  • Comment generation quality is bounded by CodeSearchNet docstring quality, which varies across repositories.
  • BLEU is reported as a design target — the report documents the actual achieved score after the training run.
  • The checker targets Python 3 only; other languages are out of scope.
  • Security rules flag suspicious patterns but do not perform taint tracking, so some findings need human confirmation.

Frequently Asked Questions

How is this different from a linter like pylint?

Linters check style and simple errors. This project adds a transformer model that understands code semantics (drafting docstrings, explaining issues) and a documented rule engine built from scratch, which gives you genuine viva material about how both layers work.

Which dataset trains the model?

CodeSearchNet's Python subset — roughly 457,000 real function–documentation pairs from open-source GitHub projects. It is the standard public dataset for code intelligence tasks.

Can it find real bugs?

The AST rules catch real structural defects (mutable defaults, bare excepts, SQL injection patterns) with exact precision on their patterns; the report's test suite shows measured precision/recall per rule. The model layer drafts documentation rather than claiming to find novel bugs.

Does it work on my own code?

Yes — paste any Python 3 snippet into the demo. Very long files are truncated at a documented limit for demo responsiveness.

What do I need to run it?

Python 3.11, PyTorch and the Hugging Face Transformers library; fine-tuning needs a GPU, inference runs on CPU.

Is this project suitable for a final-year project?

Yes — for Computer Science, IT and AI/ML programs. It combines program analysis with transformer-based code models and ships a genuinely usable tool. Suitable for B.E./B.Tech final-year projects in Computer Science, IT and AI & Machine Learning.

Components & software requirements
  • Python 3.11, ast module (static analysis core)
  • Hugging Face Transformers, CodeBERT (microsoft/codebert-base)
  • CodeSearchNet Python subset (training data)
  • PyTorch (fine-tuning)
  • Flask (demo backend) + HTML/CSS/JS (demo frontend)
  • pytest (rule test suite)

Dataset & model details

  • Dataset: CodeSearchNet (Husain et al., 2019) — 2M+ (function, documentation) pairs mined from open-source GitHub repositories across 6 languages; the Python subset (~457k pairs) is used for fine-tuning. Source: github.com/github/CodeSearchNet.
  • Task: Code-to-text generation (draft a docstring/comment for a given Python function) plus AST-based defect detection as the deterministic layer.
  • Model: CodeBERT (microsoft/codebert-base, 125M parameters) fine-tuned on CodeSearchNet Python pairs for comment generation; static rules implemented as ast.NodeVisitor subclasses.
  • Metrics: BLEU score on a held-out CodeSearchNet Python split for comment generation (design target, not a claimed result); per-rule precision/recall measured on the shipped labeled test suite and reported honestly in the report.
Delivery information

Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.

Support terms

Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.

Download abstract (PDF)

Related guides

All guides
Illustration of object tracking showing video frames with bounding boxes and persistent ID labels following people and vehicles, comparing motion prediction and appearance matching.B.E./B.Tech Computer Science and Electronics students building video analytics projects — people counting, vehicle tracking, sports analysis — who have detection working and need

Object Tracking: DeepSORT and ByteTrack Explained

Detection finds objects per frame; tracking keeps their identities across frames. This guide explains tracking-by-detection, Kalman motion models, DeepSORT's appearance embeddings vs ByteTrack's low-confidence box recovery, tracking metrics (HOTA, IDF1, ID switches), and the tuning parameters that determine real-world quality.

Read guide
Illustration of image segmentation showing U-Net's U-shaped encoder-decoder with skip connections producing pixel masks, alongside Mask R-CNN detecting instances with masks.B.E./B.Tech Computer Science and AI/ML students moving from image classification or detection to pixel-level understanding — medical imaging, defect detection, autonomous driving

Image Segmentation: U-Net and Mask R-CNN

When projects need pixel-level answers, segmentation delivers. This guide explains semantic vs instance vs panoptic segmentation, U-Net's encoder-decoder with skip connections, Mask R-CNN's parallel mask head, Dice and IoU evaluation, paired augmentation, and how to choose the right architecture for your data and question.

Read guide
Illustration of Whisper speech-to-text showing sound waves flowing into a neural network and emerging as transcribed text with timestamps and speaker labels.B.E./B.Tech Computer Science and AI/ML students adding speech-to-text to projects — voice assistants, meeting transcription, accessibility tools

Whisper for Speech-to-Text in Student Projects

Whisper transcribes speech in dozens of languages with no training required. This guide covers how it works, choosing among model sizes, running it locally with faster-whisper, handling hour-long audio, timestamps and speaker diarization, multilingual quirks, and honest evaluation with word error rate.

Read guide
Get a quotation