[{"data":1,"prerenderedAt":123},["ShallowReactive",2],{"work-legal-contract-extraction-fine-tuning":3,"work-next-\u002Fwork\u002Flegal-contract-extraction-fine-tuning":120},{"id":4,"title":5,"accent":6,"body":7,"client":84,"cover":85,"coverAlt":86,"description":87,"duration":88,"extension":89,"featured":90,"industry":91,"meta":92,"navigation":93,"order":94,"path":95,"quote":96,"results":97,"seo":107,"services":108,"stack":109,"stem":117,"year":118,"__hash__":119},"work\u002Fwork\u002Flegal-contract-extraction-fine-tuning.md","Fine-tuned LLM for clause extraction from commercial contracts","#0891B2",{"type":8,"value":9,"toc":76},"minimark",[10,20,25,28,32,56,60,69,73],[11,12,13,14,18,19],"p",{},"A contract-lifecycle software company was using a prompted frontier model to extract clauses from customer contracts. Accuracy plateaued and per-document costs were eating margin. Through our ",[15,16,17],"code",{},"ai-fine-tuning"," practice we fine-tuned an 8B open-weight model with LoRA on the client's own annotated contracts, lifting field-level F1 from about 0.91 to 0.96 "," while cutting inference cost by roughly 85%. ",[21,22,24],"h2",{"id":23},"challenge","Challenge",[11,26,27],{},"The product extracted more than forty clause types (governing law, termination triggers, indemnity caps, auto-renewal terms) from contracts in inconsistent formats. Prompt engineering had squeezed out most of the gains available; edge cases such as nested exceptions and cross-references kept failing, and every extra example in the prompt increased cost. The client had thousands of reviewed contracts but no clean training set, and no in-house ML engineers.",[21,29,31],{"id":30},"what-we-built","What we built",[33,34,35,40,43,46,53],"ul",{},[36,37,38,39],"li",{},"A data programme first: we converted lawyer-reviewed extractions from the product's own history into a training set of about 6,000 contracts ",", with a Label Studio workflow to resolve disagreements and a held-out test set that never touched training.",[36,41,42],{},"LoRA fine-tuning of Llama 3.1 8B with instruction-formatted examples, tuned for structured JSON output and calibrated abstention on clauses that are absent.",[36,44,45],{},"An evaluation harness scoring per-field precision and recall, error slices by contract type and length, and side-by-side comparison with the prompted frontier baseline on every run.",[36,47,48,49,52],{},"Serving with vLLM on the client's AWS account, an A\u002FB rollout behind their existing API, and a retraining pipeline triggered when reviewers correct enough new examples (",[15,50,51],{},"open-source-ai",").",[36,54,55],{},"Documentation and a training session so the client's engineers can rerun the pipeline themselves.",[21,57,59],{"id":58},"results","Results",[11,61,62,63,64,65,68],{},"Field-level F1 rose from around 0.91 to 0.96 on the held-out set ",", with the largest gains on the nested and cross-referenced clauses that had caused the most support tickets. Cost per contract dropped by roughly 85% ",", and median latency fell to a level that let the client show extractions live during upload rather than by email later. Related pillar: ",[15,66,67],{},"nlp"," for the pre-processing and section segmentation.",[21,70,72],{"id":71},"what-made-the-difference","What made the difference",[11,74,75],{},"Most of the effort, and most of the gain, went into the dataset, not the training run. Cleaning labels, agreeing definitions with the client's lawyers and building a trustworthy test set turned fine-tuning from an experiment into a repeatable process the client now runs without us.",{"title":77,"searchDepth":78,"depth":78,"links":79},"",2,[80,81,82,83],{"id":23,"depth":78,"text":24},{"id":30,"depth":78,"text":31},{"id":58,"depth":78,"text":59},{"id":71,"depth":78,"text":72},"Legal-tech provider · contract lifecycle software (US)","\u002Fcovers\u002Fwork\u002Flegal-contract-extraction-fine-tuning.svg","Abstract navy cover with a rising cyan course line","A domain-adapted model that pulls parties, dates, obligations and unusual clauses out of contracts with accuracy a general-purpose model could not reach at the same cost.","11 weeks","md",false,"SaaS & Technology",{},true,16,"\u002Fwork\u002Flegal-contract-extraction-fine-tuning",null,[98,101,104],{"value":99,"label":100},"0.91 → 0.96","field-level F1 vs. the prompted frontier model",{"value":102,"label":103},"~85%","lower inference cost per contract",{"value":105,"label":106},"40+","clause types extracted",{"title":5,"description":87},[17,67,51],[110,111,112,113,114,115,116],"Llama 3.1 8B","LoRA \u002F PEFT","Hugging Face","Axolotl","vLLM","Label Studio","AWS SageMaker","work\u002Flegal-contract-extraction-fine-tuning","2025","ppXFxuEQqKOZW-ailt7bznukfvtUSa922yhx2OzqV9c",{"path":121,"title":122},"\u002Fwork\u002Fproptech-ai-saas-mvp","AI SaaS MVP for a property-management startup",1792973684227]