GC Rules API
A proof of concept exploring what happens when Government of Canada program rules live as structured data instead of scattered across web pages, PDFs, and internal systems.
Not an official Government of Canada product. This is a personal experiment for demonstration and discussion purposes only. The rules and amounts may not be current.
The idea
Encode each program's rules, thresholds, rates, and examples once — in machine-readable JSON files — then generate every downstream artefact from that single source. Update one number in the JSON, and every channel updates automatically.
Five channels, one source
The same JSON files (programs/*.json) power all five of these:
Benefits Estimator
An interactive calculator for CCB, EI, and OAS. Enter your situation, get your estimated amounts. All calculation logic runs in your browser — reads the JSON, applies the rules, shows the result.
API Explorer
Browse the REST API endpoints: list programs, read parameters, check eligibility, calculate benefits. See the exact JSON responses — simulated client-side, identical output to the real FastAPI server.
Static Canada.ca page
A Canada.ca-style "How much you can get" page for the Canada Child Benefit. Generated by a Python script that reads the JSON — every amount, threshold, and example comes from the data.
LLM Chatbot
Two chatbots — local (Ollama) and cloud (Claude API) — that answer questions by reading Markdown fact sheets derived from the JSON. No hallucinated numbers, because the model only sees the actual data.
python chat.py or python chat_claude.py
Program Editor
A web form for policy analysts to update program parameters — rates, thresholds, amounts — without editing JSON. Preview changes as a diff, then download the updated file.
Programs included
How to run locally
# Serve the static files (webapp, static site, JSON)
python -m http.server 3000
# Open http://localhost:3000/webapp/
# Or run the real API server
pip install -r requirements.txt
uvicorn api.main:app --reload --port 8000
# Open http://localhost:8000/docs for Swagger UI
# Chat with a local LLM
pip install ollama
ollama pull qwen2.5:7b-instruct-q4_K_M
python chat.py
# Chat with Claude (needs API key in secrets/config.json)
pip install anthropic
python chat_claude.py
The architecture
programs/*.json ← Single source of truth (rules, rates, thresholds, examples)
│
├── webapp/ ← This site (estimator + API explorer + editor, client-side JS)
├── site/build.py ← Static Canada.ca HTML pages (generated)
├── md_export.py ← Markdown fact sheets → LLM chatbot (chat.py, chat_claude.py)
└── api/main.py ← REST API (FastAPI)
↑ editor.html ← Policy analysts update parameters here, download valid JSON
Change a number in the JSON, rebuild, and all four channels reflect the change.