Answer legal questions with Groq using CanLII and CourtListener
Go to WorkflowDescription
Quick overview
This workflow collects a legal question via an n8n form, retrieves supporting authorities from CourtListener or CanLII, and uses a Groq-hosted Llama model to produce an answer grounded only in the retrieved text with verified, non-hallucinated citations.
How it works
Receives a legal question through an n8n form and captures the selected source database (CourtListener or CanLII) plus optional CanLII database and case IDs.
Routes the request to CourtListener full-text search or to CanLII case metadata and citator endpoints based on the selected database.
For CourtListener, pulls the top search results and fetches the full text of the top-ranked opinion; for CanLII, loads the selected case and a list of related cases from the CanLII citator.
Normalizes the retrieved items into a single numbered “sources” block with excerpts that the model can cite.
Sends the question and sources to a Groq Chat Model (Llama 3.3 70B) and parses the response into a structured format containing an answer, a supported flag, and a list of citations.
Verifies every cited source index against the retrieved sources, drops any mismatches, and renders an HTML result page showing the answer, verified citations, and a disclaimer.
If any retrieval step fails, returns an error page explaining that no sources were retrieved and no answer was generated.
Setup
Add credentials for CourtListener (HTTP Header Auth token), CanLII (HTTP Query Auth API key), and Groq (Groq API credential).
If using CanLII mode, provide a valid CanLII database ID and case ID when submitting the form (for example, a court database like csc-scc and a decision ID like 2024scc1).
Review and adjust the research settings (result count, language, citator direction, snippet length, and disclaimer text) in the configuration step before activating the workflow.
Requirements
n8n with the built-in LangChain nodes/
A CourtListener API token (Header Auth) for US case law.
A CanLII API key (Query Auth) if you use CanLII mode; CanLII issues API keys on approval.
A Groq API credential; the free tier is enough to test.
Customization
Set result count, response language, and citator direction (citing vs cited cases) in the configuration node.
Adjust the source-excerpt length the model may cite, and edit the disclaimer text on the result page.
Swap the Groq model for any other supported chat model.