Public
Canadian judgment analyzer, highlights citation-worthy passages
aicanadacase-analysislegalreact
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

CaseLens Canada

A polished, Canadian-legal reader that helps users analyse a court or tribunal decision. Upload a judgment (PDF, DOCX, or plain text), and CaseLens:

  • Parses it into numbered paragraphs and reads the case header — neutral citation, court, decision date, justice(s), style of cause, and docket number.
  • Identifies citation-worthy passages and highlights them verbatim, in place, against the categories in the legend below.
  • Explains each highlight in a right-side panel: what the judge is saying, why it matters, the legal type (ratio, test, application, finding, credibility, procedural, remedy, obiter, definition), a suggested proposition, and how to cite it.
  • Lets the user mark passages Saved / Not useful, add notes, and export the saved set (copy, .txt, .md).

The full uploaded judgment stays central — CaseLens never replaces it with a summary, and it never invents citations, parallel citations, history, or treatment. Anything it cannot confidently extract is shown as "Not detected".

Try the app

Analytics engine

  • Default (no key): a built-in, transparent heuristic engine (regex + rules in server/analyze.ts) that works out of the box and is labelled in the UI.
  • AI (recommended): set an ANTHROPIC_API_KEY and the pipeline uses Claude for deep, structured extraction (server/ai.ts). CLAUDE_MODEL optionally overrides the default model.

👉 Add ANTHROPIC_API_KEY here: https://www.val.town/x/justinstevens/caselens-canada/environment-variables?key=ANTHROPIC_API_KEY

When AI is enabled, every highlight is still anchored to a verbatim substring of the uploaded text; candidates that can't be anchored are dropped. If the AI call fails, the app transparently falls back to the heuristic engine.

How anchoring works

  1. server/text.ts segments the document into paragraphs (preserving numbers/headings) and extracts case metadata (best-effort, honest).
  2. The engine produces highlight candidates with an exactQuote — AI or heuristic.
  3. server/analyze.ts finds each quote as a character-exact substring, records startChar/endChar offsets, and dedupes overlapping spans (keeping the more important one).

Architecture

Rendering mermaid diagram...
  • index.ts — Hono HTTP entrypoint; serves the SPA and /api/analyze.
  • server/text.ts, server/analyze.ts, server/ai.ts — the analysis pipeline.
  • frontend/ — React SPA (landing, progress, two-pane reader, export).
  • frontend/demo.ts — a clearly-labelled fictional sample judgment used by the "Try the sample judgment" button.
  • types.ts — shared types + the highlight legend (single source of truth for categories and colors).

Highlight legend

CategoryMeaning
Ratio / core holdingthe binding principle the decision turns on
Legal test / rulea test, standard, or governing rule
Application / reasoningapplying the law to the facts
Key factual findinga fact the court relies on
Credibility findingreliability / weight of evidence
Procedural rulingjurisdiction, standing, admissibility, process
Remedy / disposition / orderthe operative order
Notable obiterpersuasive, non-binding comment
Definitiondefinition or interpretation adopted

Privacy

Documents are parsed in the browser; only the extracted plain text is sent to CaseLens for analysis. No document is retained server-side.

Important limitation

CaseLens Canada analyses the text you upload only. It does not determine whether a case is still good law — that requires a citator (e.g. keyCite/CanLII treatment checking) which is not connected. Use this tool to accelerate reading, not to replace your own research.

View source

Every page links to this val's source at /source.

Run the pipeline standalone with server/selftest.ts.