Large language models in LegalTech
Tapping into what LLM Agents can do for a Chatbot built around the EU AI Act.
Tapping into what LLM Agents can do for a Chatbot built around the EU AI Act
Applications built on LLMs are popping up in fields such as Customer Service, the Medical domain, and Legal Tech. Customer Service (acting as a single point of contact across multiple platforms) and the medical domain (e.g. the Meditron model, tailored to medicine) have made big strides; in Legal Tech, however, wider adoption is still limited.
This post looks at using LLMs in LegalTech, beginning with why it is hard. Then we will briefly outline how the EU AI Act is structured (we use it as a resource in our example), present an agentic framework named CrewAI, and show an email-writing system that introduces the changes brought by the EU AI Act.
What makes LegalTech hard?
First, let’s look at why LegalTech is so challenging. You have likely gone through agreements or bylaws in which the wording is extremely precise and full of references to reactive legal code, along with cross-references to articles of other bills.
As for precise wording, “possession” and “ownership” are good examples: to a layperson they mean roughly the same thing, but in legal language they apply to entirely different situations.
Another key issue is that the law keeps evolving: some bills get overridden (e.g., the US Senate passing a bill on increasing the debt ceiling), while some old laws remain in effect (e.g., in Ohio, you can’t make faces to the dog).
Finally, there is the question of how the law is applied in various countries. In the US, precedents can be invoked in a court of action (something often seen in TV series), whereas in civil-law countries precedents carry far less weight than in the US. This shows how lawyers’ strategies differ from country to country.
LLM applications tend to make approximation errors at each step (and “close enough” is a poor approach where law is concerned), so pipelines built on LLM agents could be a way to address this issue.
Current LegalTech solutions based on large language models
This Stanford paper provides an insightful analysis of the errors and present performance of popular RAGs used in LegalTech (among them Lexis+ AI Westlaw, Practical Law, and GPT-4).
Their analysis suggests there is plenty of room for improvement (even the top performer still hallucinates on 17% of the queries).
Every solution fell prey to the RAG assumption that “similar texts are relevant” and hallucinated considerably on queries tied to a particular jurisdiction or point in time, where the supplied groundings didn’t fit the answer.
What’s more, most of the solutions carry a genuine risk of giving incomplete answers that lack sufficient grounding.
EU AI Act

The EU AI act risk pyramid, following the definition from: https://digital-strategy.ec.europa.eu/en/policies/regulatory-framework-ai
EU AI Act - what is it about?
Over the last few months, everyone has been talking about the EU AI Act, since it is the first regulatory initiative of its kind for AI. It is fairly easy to read and doesn’t refer to many other bills (if you’re interested, I can recommendhttps://artificialintelligenceact.eu/ai-act-explorer/).
At its heart, it establishes a pyramid of risks mapped onto four risk levels: unacceptable risk (prohibited practices), high risk (regulated high-risk systems), limited risks (transparency required), and low and minimal risk (with no obligations).
Technical look at the dataset
Given that it isn’t overly complex and is the first regulation of its kind, it makes a sensible choice for our agent example, so we picked it as one of our resources.
Technically speaking, the EU AI act contains over 78k words and consists of 13 chapters (113 articles in total) and 13 annexes (so far).
Building an agentic workflow
CrewAI - a straightforward agentic framework for complex tasks
There are many frameworks for building an AI agentic workflow (at least 3): Langgraph by the Langchain team, AutoGen by Microsoft, and lastly CrewAI – the one we’ll use in this post because it is simple and easy to work with.
CrewAI is structured quite simply, split into tools, agents, and tasks.
Tools
It provides a broad range of tools, from general-purpose web scrapers, through specialised file readers (e.g., PDF or Markdown), to dedicated search tools (e.g. Github or YouTube).
Agents
Agents are described by three key parameters:
- their role within the pipeline (e.g. Analyst)
- their goal - what they aim to accomplish (e.g. write a report from the retrieved information)
- their backstory - which shapes their character and behaviour.
Tasks
Tasks, in turn, are described by:
- a description of the task
- the assigned agent
- expected output - a specification of what we want to get as output.
Setup
Configuring the agents
For this problem, we set up 3 agents, each with its own tasks:
- Senior Paralegal, who does the bulk of the research and writes the general report on legal changes relevant to the client’s situation under the EU AI Act.
- Law Associate - builds on the paralegal’s report, adds broader legal knowledge of the sector, and identifies risks and benefits for the client’s sector once the EU AI act takes effect.
- Senior Partner - writes a clear email to the client with a personal touch, turning legal jargon into language that is easier to follow.
Here, there is no leader, and the agents work one after another (the output of each one is passed as additional input to the next.
Configuring the tools
As for tools, the Senior Paralegal and the Law Associate can use Google and perform deeper web scraping of the EU AI Act website to collect useful information. The Senior Partner only rewrites the associate’s report in plainer language for the client.
In this experiment, every agent used GPT-4o as its backend LLM because of its large context window.
Results
Here, we qualitatively compare the answers produced by two setups:
- Plain chatGPT fed with the given input.
- The agentic workflow described above
Input prompt given to ChatGPT
The input passed to chatGPT using GPT4-o is shown below:
The output of the plain request to ChatGPT using gpt4-o is shown below:
The output of the agentic workflow is shown below:
Comparison
The plain ChatGPT output reads more like a passage lifted from the bill or an article, whereas the agentic workflow’s output is far more engaging and easier to grasp.
In addition, some chatGPT response iterations cited articles that didn’t match the facts and lacked relevant legal grounding.
Bonus: AgentOps - observability for LLM Agents
Because console output can be somewhat messy and hard to read, other tools exist that make it easier to understand and follow what is going on. AgentOps is one of them.
What does it look like?
With just a few lines that call agent ops and set the right API keys, you can see the following and keep better track of costs (agents are more expensive to run because they need several sequential LLM requests), processing time (more requests = longer processing), communications, and intermediate outputs.
Conclusions
In this post, we explained why LegalTech is hard for LLMs, went over the EU AI Act basics once again, discussed the Crew AI framework for building agentic workflows, showed sample output for legal advice, and briefly compared plain chatGPT with agentic workflows.
As a bonus, we looked at AgentOps as an observability tool that helps us better understand how the system we built behaves.
If you’d like to unlock everything AI can offer with expertly built LLMs, don’t hesitate to contact us. I’d be glad to talk about your use case.