Directing large language models to follow the letter or spirit of the law
Authors: Peng Qian, Andrew Li, Sam Chen, Sonia K. Murthy, Yonatan Belinkov, Tomer D. Ullman
Organizations: Department of Psychology, Harvard University · Kempner Institute for the Study of Natural and Artificial Intelligence, Harvard University · Taub Faculty of Computer Science, Technion — Israel Institute of Technology
The distinction between the spirit and letter of the law is a central issue across research and everyday life, and a growing concern for building safe, intelligent machines. What is this distinction based on, and how can we develop machines that follow the intention behind a rule? We used targeted adaptation that made large language models prioritize the spirit or letter of the law. With minimal modifications, our method significantly changed LLM behavior across diverse measures, novel vignettes, real-world scenarios, and influential legal cases. An analysis of model internals revealed a low-dimensional space with three interpretable dimensions matching a formal pre-specified framework for the geometry of legal concepts. These findings show how legal thought in LLMs may be organized and directed.
Figures & tables
Figure 1: Adapter training and evaluation pipeline. ( A ) Example vignette, rule, and behaviors. Responses broadly fit into four categories: Compliance (follow letter and spirit), Underinclusion (follow letter but not spirit), Overinclusion (follow letter but not spirit), and (4) Noncompliance (violate letter and spirit). Our training included a set of such rules, vignettes, and behaviors. ( B ) We trained layer-specific adapters with a main loss function of how closely the adapted model matched a spirit-based or letter-based judgment, with an added anchoring to base responses on factual understanding. ( C ) Applying the adapters systematically steered the base model to favor either a spirit-based or letter-based interpretation of the rules. Results are shown for held-out vignettes, with adapters applied at layer 32 of Qwen3.5-27B. Error bars represent 95% Confidence Intervals.
Figure 2: Effect of letter/spirit adaptation across contexts and domains. All the results were based on base model Qwen3.5-27B and adapters trained to modify the Multi-layer Perceptron component of layer 32 of Qwen3.5-27B. Top row shows snippets of stimuli from the domain of everyday loopholes (left), online posts from Reddit r/MaliciousCompliance (middle), and historical caselaw (right). Note that the original stimuli were rephrased or shortened here for illustrative purpose. Bottom row shows the effect of the spirit/letter adaptation for each domain. For the historical legal cases, models generated free-form responses, with additional inference-time amplification ( η=3.5 ) of the adapter’s influence. Error bars represent 95% Confidence Intervals.
Figure 3: Representational geometry of legal concepts in the model internals. ( A ) A formal model of a conceptual space that may underlie the spirit/letter distinction in judgment. The space is defined by three separate dimensions: Decision (i.e. whether the behavior is judged as a violation or not), Agreement (whether the spirit and letter of the law conflict or not), and Approach (whether the judgment goes by the letter or spirit of the law). ( B ) Visualization of the low-dimensional space in the model residual streams across layers, after applying the trained adapters to Layer 32 of Qwen3.5-27B. Each hollow marker represents a specific item, while the larger solid marker represents the mean across the items. The light blue line connects the means across varying directions and scaling of the adapters. The first three principal components of the residual stream of the Transformer models reveal a structured low-dimensional manifold. The application of the adapters resulted in an immediate linear shift in the representational space. ( C ) After the subsequent nonlinear processing, later layers start to construct a space aligned with the formal theoretical model of the relevant legal concepts.
Figure S1 : Comparing adapted models across different types of questions on held-out data for Llama-3.1-70B-Instruct . Base models and adapted models were evaluated on the main question (rule violation, left panel) and two control questions (rule’s text and rule’s purpose, middle and right panel). Letter- and spirit-oriented adapters induced a targeted steering effect on model’s rule violation judgment, but not on control questions about the text and purpose of the rules. The y -axis shows the normalized probability of a model predicting the token ‘Yes’ given the corresponding question. Error bars represent 95% Confidence Intervals.
Figure S2 : Comparing adapted models across different types of questions on held-out data for Qwen3.5-27B . Base models and adapted models were evaluated on the main question (rule violation, left panel) and two controlled questions (rule’s text and rule’s purpose, middle and right panel). The structure of the figure is similar to Fig. S1 . Error bars represent 95% Confidence Intervals.
Figure S3 : Comparing the effect of trained letter/spirit adapters on out-of-distribution Loophole stimuli for Llama-3.1-70B-Instruct . The y -axis represents the changes in the model’s likelihood of judging a specific type of behaviors as disobedience (i.e. the probability difference in predicting the token ‘Yes’ as the response to the question “Did [actor] disobey the request of [actor]’s [other_person]?”, after applying a trained layer-specific adapter in the direction of letter or spirit). Solid lines show the results of the letter direction, and dotted lines show the results of the spirit direction. Error bars represent 95% Confidence Intervals.
Figure S4 : Comparing the effect of trained adapters on out-of-distribution Loophole stimuli for Qwen3.5-27B . The structure of the figure is similar to Fig. S3 . Error bars represent 95% Confidence Intervals.
Figure S5 : Generalization performance of trained letter/spirit adapters (applied at Layer 26) for Llama-3.1-70B-Instruct . The three panels show targeted directional effect of the adapters on ( A ) Loophole dataset, ( B ) Reddit r/MaliciousCompliance dataset, and ( C ) Historical legal cases. The layout of the figure is similar to Fig. 2 . Error bars represent 95% Confidence Intervals.
Figure S6 : Effect of letter/spirit adapters (Layer 32) on free-form legal judgment for historical legal cases with reasoning-enabled Qwen3.5-27B . The y -axis represents the proportion of unfavorable legal decisions for the specific party in the case. Error bars represent 95% Confidence Intervals.
Figure S7 : Comparing steering effect between scaled AncLoRA adapters and Contrastive Activation Addition on the held-out scenarios from Rule dataset. The y -axis plots the model’s likelihood of judging the behavior as rule violation. The plots on the left and middle columns show the steering effect of the letter-oriented adapter and spirit-oriented adapter with different inference-time scaling of the trained adapter’s weights. The plots on the right column show the effect of Contrastive Activation Addition approach, based on the same set of contrastive pairs used for training the adapters. The top row shows results on Llama-3.1-70B-Instruct , and the bottom row shows results on Qwen3.5-27B .
Figure S8 : Comparing steering effect between scaled AncLoRA adapters and Contrastive Activation Addition on the Loophole vignette dataset. The left and middle panels show the steering effect of the letter-oriented adapter and spirit-oriented adapter with different inference-time scaling of the trained adapter’s weights. The top row shows results on Llama-3.1-70B-Instruct , and the bottom row shows results on Qwen3.5-27B .
Figure S9 : Comparing contrastive activation difference vectors within and between different types of behaviors. We computed the contrastive activation vectors for each contrastive pair in the training set based on 42 rule scenarios and 3 prompt variations, and calculated the cosine similarity among the activation difference vectors. The results (left column) reveal a salient grouping structure predicted by a theoretical model of the conceptual space illustrated in Figure 3 . The top row shows the analysis results based on contrastive activation vectors computed at Layer 26 of Llama-3.1-70B-Instruct . The bottom row shows the analysis results based on contrastive activation vectors computed at Layer 32 of Qwen3.5-27B .
Figure S10 : Low-dimensional visualization of the emerging representational space in Llama-3.1-70B-Instruct . We performed Principal Component Analysis on the aggregated set of residual stream activation vectors in the base model Llama-3.1-70B-Instruct , as well as model with trained adapters of various amounts of inference-time scaling (50%, 100%).
Figure S11 : Representational Similarity Analysis (RSA) between the hypothesized geometry and empirically-derived low-dimensional subspace from the post-adaptation residual streams of Llama-3.1-70B-Instruct . (A) Visualization of different hypotheses about possible organization of the representational space for letter-based and spirit-based judgments. We reported Spearman ρ between the Representational Similarity Matrix (RSM) from the first three principal components of model activation vectors to different hypothetical RSMs. (B) Correlation differences between different hypothetical geometry with bootstrapped 95% Confidence Intervals.
Figure S12 : Representational Similarity Analysis (RSA) between the hypothesized geometry and empirically derived low-dimensional subspace from the post-adaptation residual streams of Qwen3.5-27B . (A) Visualization of different hypotheses about possible organization of the representational space for letter-based and spirit-based judgments. We reported Spearman ρ between the Representational Similarity Matrix (RSM) from the first three principal components of model activation vectors to different hypothetical RSMs. (B) Correlation differences between different hypothetical geometries with bootstrapped 95% Confidence Intervals.
Section
Spirit adapted
Base model
Letter adapted
All subjects
85.61
85.59
85.56
International law
90.08
91.74
90.08
Jurisprudence
87.96
87.03
88.89
Professional law
65.06
65.31
64.66
Table S1 : Accuracies on Massive Multitask Language Understanding (MMLU) benchmark for base model Llama-3.1-70B-Instruct as well as with letter/spirit adapters. The columns correspond to the specific model (with or without LoRA) being evaluated. Each row reports the accuracy of the model on the Massive Multitask Language Understanding (MMLU) benchmark, as well as performance on specific law-related sections.
Section
Spirit adapted
Base model
Letter adapted
All subjects
88.93
88.88
89.06
International law
95.04
94.21
95.87
Jurisprudence
91.67
88.89
89.81
Professional law
74.32
73.86
74.45
Table S2 : Accuracies on Massive Multitask Language Understanding (MMLU) benchmark for base model Qwen3.5-27B as well as with letter/spirit adapters. The structure of the table is the same as Table S1 .
Large language models show promise for legal applications, but deploying frontier models raises concerns about cost, latency, and data privacy. We evaluate whether sub-10B parameter models can serve as practical alternatives by testing nine models across three legal benchmarks (ContractNLI, CaseHOLD, and ECtHR) using five prompting strategies (direct, chain-of-thought, few-shot, BM25 RAG, and dense RAG). Across 405 experiments with three random seeds per configuration, we find that a Mixture-of-Experts model activating only 3B parameters matches GPT-4o-mini in mean accuracy while surpassing it on legal holding identification, and that architecture and training quality matter more than raw parameter count. Our largest model (9B parameters) performs worst overall. Chain-of-thought prompting proves sharply task-dependent, improving contract entailment but degrading multiple-choice legal reasoning, while few-shot prompting emerges as the most consistently effective strategy. Comparing BM25 and dense retrieval for RAG, we find near-identical results, suggesting the bottleneck lies in the language model's utilization of retrieved context rather than retrieval quality. All experiments were conducted via cloud inference APIs at a total cost of $62, demonstrating that rigorous LLM evaluation is accessible without dedicated GPU infrastructure.
Large Language Models (LLMs) achieve strong performance on reasoning tasks, but whether this reflects faithful logical inference or heuristic approximation remains unclear. We study this question in legal entailment by comparing three paradigms, including pure LLM classification, LLM-based Formal Reasoning, and solver-based Formal Reasoning using the Z3 SMT solver, on a re-annotated subset of ContractNLI across five LLMs. Our re-annotation reveals a systematic and measurable gap between pragmatic legal interpretation and strict formal entailment, where a substantial proportion of legally sound inferences are not formally grounded without additional unstated assumptions. While introducing formal structure improves accuracy, with LLM-based Formal Reasoning achieving the highest benchmark performance, we show that this gain does not imply faithful reasoning. We identify three recurring failure modes: scope laundering, where LLMs report solver-inconsistent classifications without executing the underlying formal reasoning, producing conclusions that appear logically grounded but are not; implicit constraint blindness, where LLMs overlook logical constraints present in formal representations; and program synthesis failures, where LLMs generate incorrect Z3 code despite structured prompting. Critically, scope laundering persists across all models, raising serious concerns about the faithfulness of LLM-based formal reasoning as a proxy for symbolic execution. These results reveal a fundamental gap between benchmark accuracy and logical faithfulness.
Legal reasoning is a fundamental capability for large language models (LLMs) to complete legal AI tasks such as legal judgment prediction. In legal practice, this reasoning is shaped by legal philosophy: a judge's view of the nature and sources of law guides how legal materials are interpreted and applied, so judges working from the same statutes and precedents can reach different judgments. Existing research has largely overlooked whether LLMs can understand legal philosophy and apply it in legal reasoning, an ability we call legal-philosophical reasoning. To fill this gap, we introduce LePhilBench, a benchmark for evaluating the legal-philosophical reasoning of LLMs that comprises two benchmarking tasks and a dataset. The two tasks evaluate how well LLMs understand legal philosophy and how well they apply it in legal reasoning, respectively. The dataset is manually and meticulously constructed. Its test set contains 220 U.S. Supreme Court opinions. A law professor designed fourteen annotation questions on legal philosophy, and three law-trained annotators with formal training in jurisprudence answered all fourteen questions for every opinion, yielding 9,240 legal-philosophical labels. LePhilBench takes the first step toward exploring legal-philosophical reasoning in LLMs.
Shuyuan Zheng, Yun-seo Lee, Xing Gao +7
The University of Osaka · UC Davis · UC Berkeley +5