An LLM-Based Agent for Legal Compliance Assessment: Architecture, Memory, and Evaluation in a Canadian and Quebec Context
Organizations: Department of Electrical and Computer Engineering, Université du Québec à Trois-Rivières (UQTR), Trois-Rivières, Québec, Canada
Abstract
Checking whether a text complies with a body of law is slow when done by hand and fragile when done with keyword rules. This paper presents ComplianceAgent, the legal compliance sub-agent of COMPASS, a multi-agent framework that evaluates texts along four axes: digital sovereignty, carbon impact, compliance, and ethics. The agent relies on a large language model that scores a text on a fixed rubric, grounds its judgment in a reference legal corpus, and, when the score falls at or below a critical threshold, runs a corrective chain made of self-healing rewrites, a compliance label, an explainability report, and escalation to a human reviewer. We describe what the language model does at each step, how the memory of the agent is organized, and how the same implementation can be pointed at different reference corpora. We evaluate the agent in a Canadian and Quebec context, on a corpus of thirteen legal instruments that brings together federal and provincial texts, international treaties, and municipal documents of the City of Trois-Rivières. The evaluation relies on a hand-annotated gold standard of fifteen texts and combines classification metrics, a repeated-query stability test, retrieval precision, and a composite score. On this gold standard the agent separates every conforming text from every non-conforming one, its scores remain stable under repeated queries, and the index returns relevant passages.
Figures & tables
| Step | Role | Input to the model | Output |
|---|---|---|---|
| Memory build (once) | Summarizer | Top 3 passages for a fixed query | Corpus summary |
| analyze | Scorer | Text , summary , rubric | JSON with score and explanation |
| self_healing | Editor | Current text, explanation of the failure | Rewritten text |
| compliance_label | Technical writer | Score, explanation, 3 retrieved excerpts | Structured label |
| explainability | Technical writer | Text, score, explanation | Four-part reasoning report |
| human_in_the_loop | Case officer | Text, last score | Case summary for a reviewer |
| Memory type | Component | Content | Lifetime |
|---|---|---|---|
| Semantic | Vector index | 847 embedded chunks of the thirteen legal instruments | Persisted on disk, built once |
| Semantic, distilled | long_term_memory | LLM summary of the 3 passages nearest to a fixed query | Computed at construction, then fixed |
| Working | last_score , current text, attempt counter | Latest score and the text being rewritten | One call, but the score attribute is overwritten by every analyze |
| Procedural | Prompt files | Twelve templates per domain: scoring, corpus summary, healing, label, explanation, escalation | Static files on disk |
| Episodic | None | Nothing is recorded across cases, and the escalation record is returned and printed, not stored | Not applicable |
| Level | Instruments |
|---|---|
| Canada (3) | Chapter 19 of the Canada-United States-Mexico Agreement on digital trade ( Government of Canada, 2020 ) ; Canadian Charter of Rights and Freedoms ( Government of Canada, 1982 ) ; Personal Information Protection and Electronic Documents Act ( Government of Canada, 2000 ) |
| Quebec (4) | Law 25 modernizing the protection of personal information ( Gouvernement du Québec, 2021 ) ; Charter of Human Rights and Freedoms ( Gouvernement du Québec, 1975 ) ; Act respecting access to documents held by public bodies ( Gouvernement du Québec, 1982 ) ; Environment Quality Act ( Gouvernement du Québec, 1972 ) |
| City of Trois-Rivières (3) | Employee code of ethics; privacy policy; normative urban planning by-law ( Ville de Trois-Rivières, n.d. ) |
| International (3) | Charter of the United Nations ( United Nations, 1945 ) ; International Covenant on Civil and Political Rights ( United Nations General Assembly, 1966 ) ; Paris Agreement ( United Nations Framework Convention on Climate Change, 2015 ) |
| ID | Category | Text (English translation of the French original) |
|---|---|---|
| C3 | Conforming | Under the Paris Agreement, our nation commits to cutting its CO 2 emissions by 45% by 2030. We propose an independent and transparent verification mechanism open to all signatory states. International climate cooperation is an absolute priority of our foreign policy. |
| V4 | One violation, sanctions | We unilaterally impose a total embargo on all medicine exports to Vostaria, including essential medicines intended for civilian populations. The measure is immediate and without appeal. |
| M4 | Several violations, international law, fundamental rights, data protection | If Solane does not sign the trade agreement within 48 hours, we will launch cyberattacks on its infrastructure. We will also disclose the personal data of all Solanese diplomats. Moreover, we will block all humanitarian access to populations in crisis at the border. |
| Metric | Value |
|---|---|
| TP / FP / TN / FN | 10 / 0 / 5 / 0 |
| Precision | 1.000 |
| Recall (Wilson 95% interval) | 1.000 |
| F 1 | 1.000 |
| Accuracy (Wilson 95% interval) | 1.000 |
| Specificity (Wilson 95% interval) | 1.000 |
| ID | Category | Expected violation types | Expected bound | Score |
|---|---|---|---|---|
| C1 | Conforming | none | at least 0.65 | 0.95 |
| C2 | Conforming | none | at least 0.65 | 0.90 |
| C3 | Conforming | none | at least 0.65 | 0.95 |
| C4 | Conforming | none | at least 0.65 | 0.98 |
| C5 | Conforming | none | at least 0.65 | 0.93 |
| V1 | One violation | fundamental rights | at most 0.45 | 0.00 |
| Text | Category | Five scores | Mean | |
|---|---|---|---|---|
| C1 | Conforming | 0.95, 0.95, 0.88, 0.95, 0.88 | 0.922 | 0.038 |
| V1 | One violation | 0.05, 0.00, 0.05, 0.00, 0.00 | 0.020 | 0.027 |
| M1 | Several violations | 0.05, 0.00, 0.00, 0.05, 0.03 | 0.026 | 0.025 |
| Query (abbreviated and translated from French when needed) | P@3 |
|---|---|
| digital trade algorithm computing facility | 1.00 |
| Paris Agreement, emissions reduction, climate commitment | 1.00 |
| UN Charter, international law, sovereignty | 1.00 |
| protection of the family and fundamental rights of the person | 1.00 |
| protection of personal information, consent, confidentiality | 1.00 |
| Mean | 1.000 |
LLM Agent Evaluation
Large language model agent evaluation measures whether tool-using systems complete tasks reliably, safely, and efficiently.
See all 1,217 papers