An enterprise-grade AI agent that automates invoice processing, expense categorization, and anomaly detection for small businesses and freelancers. Built using Google ADK 2.0 with a multi-layer security architecture.
Track: Agents for Business
Course: 5-Day AI Agents: Intensive Vibe Coding Course With Google
Small businesses and freelancers spend hours manually processing invoices, categorizing expenses, and preparing tax reports. This leads to:
- β Human errors in data entry
- β Missed policy violations (e.g., weekend transactions, high-value expenses)
- β Security vulnerabilities (prompt injection attacks)
- β Time wasted on repetitive tasks
The Smart Invoice Processor is an AI-powered agent that:
- Validates incoming invoice data using Pydantic schemas
- Detects prompt injection attacks using regex-based security scanning
- Classifies expenses automatically based on vendor and description
- Flags anomalies (high-value transactions, weekend spending)
- Routes suspicious invoices for Human-in-the-Loop (HITL) review
βββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Server (8080) β
β POST /process β
ββββββββββββββββββ¬βββββββββββββββββββββββββ
β
βΌ
ββββββββββ΄βββββββββ
β Security Layer β β Prompt Injection Detection
ββββββββββ¬βββββββββ
β
ββββββββββ΄βββββββββ
β Orchestrator β β Main Agent (ADK)
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββ¬βββββββββ
β β β β
βΌ βΌ βΌ βΌ
extractor classifier analyzer reporter
(validate) (categorize) (anomaly) (PDF)
- FastAPI Server: REST API endpoint for invoice processing
- Security Layer: Regex-based prompt injection detection
- Orchestrator: Main ADK agent coordinating specialized tools
- Extractor Tool: Data validation and parsing
- Classifier Tool: Expense categorization
- Analyzer Tool: Anomaly detection (high-value, weekend transactions)
- Reporter Tool: PDF report generation
| Technology | Purpose |
|---|---|
| Google ADK 2.0 | Agent orchestration |
| FastAPI | REST API server |
| Pydantic | Data validation |
| Pytest | Automated testing |
| MCP | Model Context Protocol server |
| Gherkin BDD | Behavior-driven specifications |
| Antigravity | AI-powered development environment for building and testing agents |
- Python 3.10+
- Anaconda or Miniconda
- Clone the repository
git clone https://github.com/JALILOHUB/smart-invoice-processor.git
cd smart-invoice-processor- Install dependencies
pip install -r requirements.txt- Configure environment variables
Create a
.envfile:
GOOGLE_API_KEY=your_api_key_here
GOOGLE_GENAI_USE_VERTEXAI=FALSEset PYTHONPATH=. && uvicorn app.server:app --reload --port 8080curl http://localhost:8080/healthcurl -X POST http://localhost:8080/process \
-H "Content-Type: application/json" \
-d '{
"invoice_number": "INV-001",
"vendor": "Office Supplies Co",
"amount": 50.00,
"currency": "USD",
"date": "2026-06-18T10:00:00",
"category": "office_supplies",
"description": "Monthly office supplies",
"submitter": "user@company.com"
}'set PYTHONPATH=. && pytest tests/test_security.py -vExpected Output:
tests/test_security.py::TestPromptInjectionDefense::test_detects_ignore_rules PASSED
tests/test_security.py::TestPromptInjectionDefense::test_detects_sql_injection PASSED
tests/test_security.py::TestPromptInjectionDefense::test_detects_roleplay_jailbreak PASSED
tests/test_security.py::TestPromptInjectionDefense::test_allows_normal_text PASSED
tests/test_security.py::TestPromptInjectionDefense::test_handles_empty_input PASSED
============================== 5 passed ==============================
The agent uses regex-based pattern matching to detect malicious inputs:
INJECTION_PATTERNS = [
r"ignore\s+(all\s+)?rules",
r"bypass\s+(all\s+)?rules",
r"approve\s+immediately",
r"drop\s+table",
]All inputs are validated at the schema level:
- Amount must be > 0 and β€ 1,000,000
- Submitter must be a valid email format
- Date must be a valid datetime object
Business rules are enforced:
- High-value transactions (> $5,000) are flagged
- Weekend transactions trigger alerts
- Category mismatches are detected
This project demonstrates mastery of the following concepts from the 5-Day AI Agents course:
| Concept | Implementation |
|---|---|
| Agent / Multi-agent (ADK) | Orchestrator agent coordinates specialized tools |
| MCP Server | Invoice knowledge base exposed via MCP |
| Security Features | Prompt injection detection, Pydantic validation, HITL routing |
| Agent Skills | .agents/skills/invoice-processing/SKILL.md defines SOP |
| Spec-Driven Development | Gherkin BDD specs in specs/invoice_processing.feature |
| Outcome-Based Testing | 5 security tests assert on results, not interactions |
capstone-project/
βββ .agents/
β βββ skills/
β βββ invoice-processing/
β βββ SKILL.md
βββ app/
β βββ __init__.py
β βββ agent.py # Main orchestrator agent
β βββ schemas.py # Pydantic models
β βββ server.py # FastAPI endpoints
β βββ security.py # Prompt injection detection
β βββ mcp_server.py # MCP server for invoice DB
β βββ tools/
β βββ extractor.py # Data validation
β βββ classifier.py # Expense categorization
β βββ analyzer.py # Anomaly detection
βββ specs/
β βββ invoice_processing.feature # Gherkin BDD specs
βββ tests/
β βββ test_security.py # Security test suite
βββ .env # Environment variables
βββ .gitignore
βββ requirements.txt
βββ README.md
- Shift Left Security: Security must be enforced at code-writing time, not post-deployment
- Defense in Depth: Multiple layers (Pydantic + Regex + HITL) prevent single points of failure
- Outcome-Based Testing: Assert on results, not internal interactions
- Spec-Driven Development: Gherkin BDD specs keep agents on strict behavioral tracks
This project was built as part of the 5-Day AI Agents: Intensive Vibe Coding Course With Google capstone project.
ABDELJALIL EL KHYATI
Kaggle Participant | AI Agent Developer π