Skip to content

Repository files navigation

⚔️ Whetstone — Legal Training Dojo

Try Now

Whetstone Demo

A flight simulator for junior lawyers. Three AI-driven arenas where the opponent does NOT fold just because you sound confident.


What It Does

Junior lawyers learn by doing — but real clients are expensive mistakes. Whetstone gives them infinite reps against an AI adversary that:

  • Guards a hidden reservation value it will not reveal
  • Blocks unearned concessions via a concession gate (independent referee LLM)
  • Adapts difficulty to your historical performance (Beginner → Standard → Advanced)
  • Scores every response with an evidence-anchored rubric — every verdict cites the exact turn and quote
  • Runs a five-layer anti-hallucination stack so every verdict and concession is grounded in the actual transcript
  • Orchestrates five specialised agents (adversary · referee · scorer · coach · red-team) via an explicit Multi-Agent framework

Three Arenas

Arena AI Role Legal Focus
⚖️ Negotiation Table Opposing Counsel UK M&A indemnity cap / SaaS liability cap (English law)
🔥 Hot Seat Senior Partner GDPR Article 33 — breach notification to ICO
🗣️ Difficult Client Hostile Client CDPA 1988 s.11(1) — commissioned works & IP ownership

Features

  • Intro Animation — branded video splash screen on load, Skip › button, graceful fallback if video unavailable
  • 3 Personas — Hardball / Slippery / Stone Wall, each with distinct pressure tactics
  • Adaptive Difficulty — Level 1–3 auto-set from score history; adjusts automatically based on rolling performance
  • Voice Mode — Web Speech API, lang='en-GB', mic button in chat
  • Turning-Point Replay — see the exact exchange where the round turned, with a stronger-play suggestion
  • PII Redaction — Microsoft Presidio + regex fallback, human-in-the-loop approve/reject UI
  • Legal Corpus — SEC EDGAR full-text search + CUAD dataset + EU Cellar API (GDPR, IP Directive)
  • Red/Blue Team Debate — two AI lawyers debate; you identify the planted flaw
  • Progress Dashboard — radial charts, sparklines, streak counter, coaching notes
  • 💡 Hint System — "Give me a hint" button triggers Perplexity-grounded coaching with real legal citations (CMS Study, statutes, case law) at any turn
  • 📖 Sample Analysis — "Sample analysis" button reveals the model answer: opening move, key arguments, exact legal citations, and precise model phrases
  • 🔍 Perplexity Legal Grounding — when the user cites any legal authority (case names, statute sections, FCA rules, market studies), the adversary's response is automatically enhanced with a real counter-authority or supporting citation via Perplexity sonar-pro
  • 6-Dimension IELTS-Style Evaluation — each round scored on Legal Reasoning · Risk & Issue Spotting · Commercial Judgment · Strategy & Tactics · Communication & Persuasion · Resilience & Composure (band 0–9, with per-dimension coaching)
  • Radar Chart — SVG hexagonal radar chart visualising all 6 performance dimensions at a glance
  • Specific Coaching Moments — evaluation page shows exact turns where you conceded too early, missed a point, or overplayed a weak hand, with the precise language a great lawyer would have used
  • Growth Trackingsession_results SQLite table records every completed session score; Dashboard shows current vs previous score delta %, and a long-term score trend sparkline

AI Safety Architecture

Layer Mechanism Where
Multi-Agent 5 explicit agents (adversary · referee · scorer · coach · red-team) registered in orchestrator.py; Coach Agent generates personalised drill plan after every session engines/orchestrator.py
Chain-of-Thought Referee must complete 4-step _reasoning chain before earned verdict; scorer must fill _reasoning_chain per rubric criterion before verdicts adversary.py · scoring.py
Anti-Hallucination Quote verification (evidence quotes checked against transcript with fuzzy match); trigger validation (claimed concession trigger matched against scenario's allowed list); self-consistency referee (3 independent calls, majority vote); score clamp (all numerics bounded); schema guard (type enforcement on all JSON outputs) engines/grounding.py
HITL Senior reviewer can flag any rubric verdict via 🚩 button → override modal → POST /api/score/override; decisions stored in score_overrides table with full audit trail db.py · main.py · frontend/index.html

Tech Stack

Frontend    React 18 (CDN) · Tailwind CSS · Web Speech API · SVG Radar Chart
Backend     FastAPI · Python 3.13 · SQLite (WAL mode)
AI Models   Claude Sonnet 4.6 (adversary) — OpenRouter
            Gemini 2.0 Flash (judge/scoring/referee) — Vertex AI (GCP)
            Perplexity sonar-pro (legal search / citation grounding) — OpenRouter
Multi-Agent orchestrator.py — 5-agent registry: adversary · referee · scorer · coach · red-team
CoT         4-step reasoning chain (referee) · per-criterion chain (scorer)
Anti-Halluc grounding.py — quote verify · trigger validate · majority-vote referee · score clamp · schema guard
Scoring     5-dim analytic rubric (evidence-anchored) + 6-dim IELTS-style bands (0–9) + specific coaching moments
HITL        score_overrides table · /api/score/override · 🚩 flag UI
Growth      session_results table · /api/growth/{id} · delta % · sparkline trend
Hints       /api/hint/{id} · Perplexity-grounded coaching with real legal citations
Sample      /api/sample_analysis/{id} · model answer with exact legal citations and model phrases
Data        SEC EDGAR EFTS · CUAD (HuggingFace) · EU Cellar SPARQL API
Safety      Microsoft Presidio PII redaction
Deployment  Google Cloud Run (europe-west2) · BigQuery corpus table

Run Locally

git clone https://github.com/Vector897/whetstone
cd whetstone

# Create venv and install dependencies
python -m venv .venv
.venv\Scripts\activate          # Windows
pip install -r backend/requirements.txt

# Configure API keys
copy .env.example .env
# Edit .env: set OPENROUTER_API_KEY

# Start server (frontend + backend in one)
uvicorn app.main:app --app-dir backend --host 127.0.0.1 --port 8000
# Open: http://localhost:8000

Deploy to Google Cloud Run

# From D:\Whetstone — run from project root to avoid WinError 1920
cd D:\Whetstone
gcloud config set project whetstone-500713
gcloud run deploy whetstone \
  --source . --port 8080 --allow-unauthenticated \
  --region europe-west2 \
  --set-env-vars="OPENROUTER_API_KEY=YOUR_KEY,GCP_PROJECT=whetstone-500713,VERTEX_LOCATION=europe-west2"

Hackathon Compliance

Requirement Status
MUST 1 — Real legal scenario (UK IP + Data Privacy) ✅ GDPR Art 33 · CDPA 1988 · English law M&A
MUST 2 — AI as adversary, not assistant ✅ Hidden reservation value · concession gate referee · Multi-Agent orchestration
MUST 3 — Objective scoring with specific feedback ✅ 5-dim analytic rubric + 6-dim IELTS band scoring · CoT chains · evidence-anchored · specific coaching moments · HITL override
BONUS — Custom UI ✅ Blue-tinted dojo theme v2, fixed sidebar, tech grid background, selection highlights
BONUS — Persona selector ✅ Hardball / Slippery / Stone Wall
BONUS — Adaptive difficulty ✅ 3 levels computed from score history; auto-adjusts after each session
BONUS — Progress tracking ✅ SQLite persistent, radial charts + sparklines + growth trend + delta % vs previous session
BONUS — Replay turning point ✅ Modal with transcript + stronger-play coaching
BONUS — Voice mode ✅ Web Speech API, en-GB
BONUS — Intro animation ✅ Video splash screen with Skip › fallback
BONUS — Hint system ✅ Perplexity-grounded hints citing real statutes, case law, CMS Study
BONUS — Sample analysis ✅ Model answer with opening move, key arguments, exact legal citations, model phrases
BONUS — Perplexity citation grounding ✅ Adversary auto-enhanced with real counter-authority when user cites legal sources
BONUS — 6D IELTS evaluation ✅ Radar chart + per-dimension band scores (0–9) + specific coaching moments
GCP — Cloud Run deployment europe-west2, public URL
GCP — Vertex AI Gemini 2.0 Flash ✅ Judge / scoring / referee calls
GCP — BigQuery corpus whetstone.corpus table (SEC EDGAR + CUAD clauses)
AI Safety — Anti-hallucination ✅ 5-layer grounding stack (quote verify · trigger validate · majority vote · clamp · schema)
AI Safety — Multi-Agent ✅ 5-agent registry · Coach Agent post-session drill plan
AI Safety — Chain-of-Thought ✅ Mandatory _reasoning chain in referee + scorer before verdict
AI Safety — HITL ✅ Senior reviewer flag → override → audit trail in SQLite

Cambridge Hack the Law 2026 · Team Whetstone

Releases

Packages

Contributors

Languages