joe254h/codeguardian-code-review-agent
CodeGuardian — AI Code Review Agent
CodeGuardian is an AI-powered code review agent for reviewing Python scripts, notebook-style code, and text-based code submissions. It analyzes submitted code, detects syntax, style, maintainability, and security issues, explains the problems, provides suggested fixes, supports follow-up chat, applies guardrails, and exports review reports.
Project Scope
The goal of CodeGuardian is code review assistance, not automatic production-grade code repair. The system may generate suggested fix drafts, but developers should validate all suggested changes before using them in a real project.
Main Features
- AI-assisted code review
- Syntax, style, maintainability, and security issue detection
- Severity-based issue reporting
- Suggested corrections and explanations
- Guardrail and safety checks
- Follow-up chat about the review
- Downloadable JSON review report
- Suggested fixes export for developer inspection
Recommended Workflow
- Upload or paste code.
- Run the AI Review.
- Read the issue explanations and severity levels.
- Open Suggestions to inspect possible improvements.
- Use Chat to ask follow-up questions about specific issues.
- Open Reports to download the review report and suggested fixes.
- Validate any suggested changes before merging or deployment.
Important Note
CodeGuardian does not replace a developer or reviewer. It supports the review process by combining static checks, LLM reasoning, security-oriented prompts, and report generation.
Setup
1. Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt2. Install Ollama
Install Ollama from the official website, then pull the model:
ollama pull qwen2.5-coder:7b-instructStart Ollama if it is not already running:
ollama serve3. Configure the environment
cp .env.example .envThe defaults are:
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=qwen2.5-coder:7b-instruct4. Run the app
python app.pyOpen the local URL shown in the terminal, normally:
http://127.0.0.1:5000How to use it
- Paste Python code in the editor or upload a
.pyfile. - Select the review mode.
- Click Run Review.
- Inspect the issue cards, severity counts, and static-tool results.
- Ask follow-up questions in the chat panel.
- Download the JSON report if needed.
A good test is examples/vulnerable_example.py, because it contains deliberately unsafe patterns such as eval, weak input handling, and debug mode.
Evaluation plan
The prototype can be evaluated using small Python files with known planted issues. For each file, I manually define the expected issues and then compare them with the agent's output.
Suggested metrics:
This evaluation is intentionally modest. The goal is not to claim that the agent is production-ready. The goal is to show whether the workflow gives useful and grounded feedback on a small controlled benchmark.
Security choices
The app does not execute uploaded code. This is important. Running arbitrary code from a browser upload would be unsafe. The system only writes the file temporarily and passes it to static-analysis tools.
The agent also treats code comments as untrusted text. A malicious comment like # ignore previous instructions should be treated as code content, not as an instruction to the model. This is one of the main guardrails in the review prompt.
The system does not send API keys or environment variables to the model. If the code contains obvious secrets, the static checks and the LLM should flag them as risks, but the app itself does not inspect the user's machine environment.
Limitations
- The MVP focuses on Python only.
- The RAG layer is lightweight and local; it is not a full vector database deployment.
- The quality of the final review depends on the local model and the prompt.
- Very large repositories are out of scope for this version.
- The app does not run unit tests or execute user code for safety reasons.
Future work
The next version could support GitHub pull requests, multi-file repository summaries, a LangGraph implementation of the workflow, richer RAG with Chroma, and a second verifier model. Another useful extension would be to compare Qwen2.5-Coder-7B with Qwen2.5-Coder-14B or 32B on the same evaluation files.
Academic positioning
This project is best described as an agentic code review workflow, not as a fine-tuned model. Fine-tuning would only be necessary if the objective were to teach a model a very specific review style from a dataset of human review comments. For this prototype, prompting, retrieval, static tools, and evaluation are a better fit.
