code-shrish/itr-detection
ITR Fraud Detection Environment ๐ฆ๐
An OpenEnv-compliant environment where AI agents learn to detect fraud in Indian Income Tax Returns (ITR). Built for the Meta PyTorch ร Hugging Face OpenEnv Hackathon.
๐ฏ What It Does
This environment simulates the work of a tax auditor at the Indian Income Tax Department. An AI agent:
- Reviews an ITR filing (income, deductions, TDS, high-value transactions)
- Investigates specific fields for irregularities
- Cross-references data points to find discrepancies
- Requests supporting documents (Form 16, rent receipts, bank statements)
- Flags anomalies with reasoning and severity
- Renders a final verdict: legitimate, suspicious, or fraudulent
This is a real-world task โ not a game. Tax auditors perform these exact steps daily to detect billions in tax fraud.
๐๏ธ Project Relevance & The AI Auditor
Why This Idea Matters
India's tax collection system is transitioning to a "Faceless Assessment" model. Manually auditing millions of ITR filings is physically impossible and prone to human error or bias. Our environment provides a training ground for AI Auditors that can:
- Scalability: Process thousands of returns per minute.
- Consistency: Apply the same audit logic to every citizen fairly.
- Complexity: Identify multi-layered "layering" techniques used in money laundering and tax evasion.
Role of Large Language Models (LLMs)
Modern LLMs (like GPT-4o, Gemini 1.5 Pro) are uniquely suited for this task because:
- Tax Law Training: These models have read thousands of pages of tax codes, case law, and IT Department circulars (Section 80C, 80D, HRA rules, etc.).
- Pattern Recognition: They are excellent at spotting inconsistencies between text-heavy descriptions (standard business books) and numerical data.
- Reasoning: Unlike traditional static rule-engines, an AI Agent can decide which document to ask for next based on previous findings, mimicking the curiosity of a human auditor.
- Explainability: They don't just flag fraud; they explain why it's fraud in natural language, making them perfect assistants for human review.
๐ Quick Start
Installation
pip install -e .Run the Baseline Agent (No API Key Needed)
python inference.py --localRun Inference Script Required by Hackathon
export HF_TOKEN="your-huggingface-or-openai-key-here"
export API_BASE_URL="https://router.huggingface.co/v1" # (Optional: defaults to OpenAI)
export MODEL_NAME="gpt-4o-mini" # (Optional: defaults to gpt-4o-mini)
python inference.pyStart the Server
python -m uvicorn server.app:app --host 0.0.0.0 --port 8000Use the Client
from client import ITRFraudEnv
from models import ITRAction, ActionType, VerdictType
with ITRFraudEnv(base_url="http://localhost:8000") as client:
# Reset for easy task
obs = client.reset(task_id="easy")
# Investigate salary
result = client.step(ITRAction(
action_type=ActionType.INVESTIGATE_FIELD,
field_name="income.salary"
))
# Render verdict
result = client.step(ITRAction(
action_type=ActionType.RENDER_VERDICT,
verdict=VerdictType.FRAUDULENT,
confidence=0.9,
explanation="Income mismatch with TDS records"
))๐ Tasks
Each task has a programmatic grader that scores performance from 0.0 to 1.0 based on:
- Anomaly detection accuracy
- Verdict correctness
- Investigation completeness
- Efficiency (fewer steps = better)
๐ฎ Action Space
Available Document Types
form_16โ Employer TDS certificatebank_statementโ Bank account recordsrent_receiptsโ For HRA verificationinvestment_proofsโ 80C/80D proofscapital_gains_statementโ Stock trading recordsbusiness_booksโ Business accountingrelated_party_recordsโ Related entity transactions
๐ Observation Space
Each observation contains:
- ITR Summary: Full tax return data (income, deductions, TDS, transactions, previous years)
- Last Action Result: What happened from the last action
- Investigation Results: Findings from investigations
- Document Results: Requested documents and any discrepancies
- Flagged Anomalies: List of anomalies the agent has flagged
- Step Info: Current step number, max steps, task description
๐ Reward Function
๐ณ Docker Deployment
# Build
docker build -t itr-fraud-env -f server/Dockerfile .
# Run
docker run -p 8000:8000 itr-fraud-env
# Test
curl http://localhost:8000/health๐ Project Structure
โโโ models.py # Pydantic Action/Observation/State models
โโโ client.py # HTTP client (ITRFraudEnv)
โโโ inference.py # Baseline inference script
โโโ openenv.yaml # OpenEnv manifest
โโโ pyproject.toml # Package configuration
โโโ tasks/
โ โโโ task_easy.py # Easy: Obvious red flags
โ โโโ task_medium.py # Medium: Subtle inconsistencies
โ โโโ task_hard.py # Hard: Multi-layered fraud
โโโ data/
โ โโโ itr_generator.py # Synthetic ITR data generator
โโโ server/
โโโ itr_environment.py # Core environment logic
โโโ app.py # FastAPI server
โโโ requirements.txt # Server dependencies
โโโ Dockerfile # Container image๐ง OpenEnv API
๐ License
MIT
