All projects

Technology

LLM Prompt Optimization for Legal-Clause Classification

Comparative research that lifted F1 from 0.62 to 0.76 on Terms-of-Service clause classification through automatic prompt optimisation alone - without retraining

Technical University of Munich NLP Research & Prompt Engineering
AI Research LLMs Legal-Tech NLP Prompt Engineering Text Classification
Legal-Clause Classification

The challenge

Nobody reads Terms of Service - yet they contain clauses that genuinely matter: the right to change terms unilaterally, mandatory arbitration, limitation of liability, an account that can be closed without notice. A system that can identify those clauses automatically lets people see what they are agreeing to.

The obvious approach is to ask a language model, but off-the-shelf prompts gave uneven results: strong on some clause types, weak on others. Retraining a model for the task is expensive and out of reach for most organisations.

Hence the research question: how far can you get by systematically optimising the prompt alone, without touching the model?

The approach

As part of a practical research course at the Technical University of Munich, I ran a comparative evaluation of automatic prompt-optimisation methods on legal clause classification.

  1. A real legal dataset. I worked on CLAUDETTE, an academic dataset of Terms-of-Service clauses labelled fair or unfair. I set up two configurations: binary (fair / unfair) and nine-class multi-label - arbitration, unilateral change, content removal, jurisdiction, choice of law, limitation of liability, unilateral termination, contract by using.
  2. Honest baselines first. To claim prompt optimisation adds anything, you have to know what it must beat: a classical TF-IDF + SVM, LegalBERT (a transformer pre-trained on legal text), and plain zero-shot and few-shot prompting.
  3. Four automatic optimisation methods compared. PromptAgent (Monte Carlo tree search over the prompt space), EvoPrompt (evolutionary search), a textual-gradient approach (improving the prompt from the model's own error analysis), and OPRO - all evaluated on the same data, the same splits and the same metrics.
  4. Output made measurable. The model was run to return schema-constrained JSON - class label plus rationale - rather than free text, so results could be scored automatically on accuracy, precision, recall and F1 without manual interpretation.

Result: the best automatically optimised prompt moved accuracy from 0.650 to 0.755 and F1 from 0.622 to 0.755 - roughly a 21% relative gain in F1, with no training step applied to the model.

The practical takeaway: the quality you get from a language model depends heavily on how you ask, and that "how" can be found by measurement rather than intuition. The same approach transfers to any classification task where changing the model isn't in the budget.

Stack: Python, Llama-3.3-70B and 3.1-8B (API), PromptAgent, EvoPrompt, OPRO, LegalBERT, scikit-learn, schema-constrained JSON output.

Want similar results for your project?

Every project above started with a conversation. Let's figure out what yours needs.

Keep exploring

More projects.

Other · A rail infrastructure engineering firm

Rail catenary pole placement automation

Weeks of expert engineering work, reduced to seconds.

View
Healthcare · Decoto International

D-Risk - MedTech Marketplace with AI Company Profiling

A three-sided marketplace linking medtech startups with investors and specialist freelancers - matched through AI document profiling.

View
Technology · Ottronic E-Systems (TUM 1000+ Project Week)

Integrated LoRa Sensor Monitoring & Analytics System

Turning raw LoRa telemetry from tree-mounted sensors into live dashboards that answer watering and growth questions - built in one week.

View
Other · A certified accountant

Revenue Administration MCP Server

An assistant that reads Turkish tax legislation from its official source at the moment you ask and answers with the article behind it - a system a certified acc

View
Technology · Fraunhofer IKS, Munich

Reliability of LLMs in Safety-Critical Requirements Engineering

A controlled experiment measuring what an ungrounded, off-the-shelf chatbot contributes to safety-critical engineering.

View
Technology · Fraunhofer IKS, Munich

DSGENAI - AI Safety Requirements Engineering Platform

Stabilising and modernising an AI-driven safety-requirements platform - Flask to Streamlit, GPT-5.1, and critical data-leak fixes.

View
Technology · Independent project

Retrieval-Augmented Generation (RAG) Documentation Assistant

A RAG assistant that turns stacks of PDFs into a searchable knowledge base where every answer traces back to the source document.

View
Technology · Siemens

Smart Contract Analysis with NLP

An NLP system learns from Siemens' legal team's past contract revisions, flags the same clauses in a new contract, and proposes the edit that was made before.

View
Other · Scoutium

Football Player Potential Prediction Model

A classification model predicting whether a player will be marked "highlighted" from 39 scout attribute scores - ROC-AUC 0.86 under 10-fold cross-validation.

View
Other · Scoutium

Football Player Ranking System

A scoring engine that ranks players not by total score, but by how many attributes they exceed the statistical average for their own position.

View
Other · Scoutium

Football Player Position Recommender System

A recommender that compares a player's attribute profile against the profiles of other positions and finds players could be more valuable in a different role.

View
Other · Turkish Airlines

Automated Connecting-Flight Optimization

A tool that recalculates every connection possible through the hub - day by day, with passenger volumes - when a single flight's time is shifted.

View
Other · Turkish Airlines

Flight Passenger-Count Prediction

A demand model predicting booked passengers on one-stop routes from a flight's own characteristics, selected by comparing eleven regression models.

View
Technology · Istanbul Bilgi University

Turkish Image-Captioning Benchmark on MS COCO 2014

A human-verified Turkish caption dataset covering all of MS COCO, plus five models trained on it - a new reference point for Turkish image captioning.

View
Finance & Fintech · CFA Poland (hackathon)

ESG Diversity & Sentiment Solution - CFA Poland Hackathon

An ESG prototype scoring gender diversity and news sentiment - 2nd place among 44 teams from 28 universities.

View
Other · Boğaziçi University IT Club (hackathon)

Automated ESG Scoring System - HackBogazici

An automated ESG scoring engine built from four scraped data sources - 2nd place among 14 hackathon teams.

View