EU law · 24 official languagesArticle-level JSON · typed citation graphMCP server · Claude, Cursor, VS CodeSDKs · Python, TypeScriptFree plan · 500 credits to start
Brussels · CET
Vol. II·Section S — Solutions Desk

§ LangChain — For developers

EU law retrievers and tools for LangChain and LangGraph.

langchain-lexapi gives a LangChain app a retriever over EU legislation, one over Court of Justice case law, and three agent tools. Every document ends with a Source: line: CELEX number, article or ECLI, EUR-Lex link. It calls the LexAPI REST API with your key; a search costs 5 credits, and the free plan starts with 500. LexAPI is not affiliated with LangChain, EUR-Lex or the Publications Office.

Create a free accountGitHubExample: RAG over EU law

LexAPI’s own package for LangChain, on PyPI
pip install langchain-lexapi
Python
from langchain_lexapi import LexAPILegislationRetriever

retriever = LexAPILegislationRetriever(k=3)  # reads LEXAPI_API_KEY
for doc in retriever.invoke("right to erasure of personal data"):
    print(doc.metadata.get("cite_celex"), doc.metadata.get("article_ref"))
    print(doc.page_content)  # the article, then its Source: line

Prints each hit’s CELEX number and article, then the text ending in its Source: line.

§ 01 — Install

Install langchain-lexapi.

You need: Python 3.11 or later and an API key

The import is langchain_lexapi; it needs langchain-core 1.4 or later. Version 0.1.0. Set the LEXAPI_API_KEY environment variable, or pass api_key=.

§ 02 — Retrieve

LangChain retriever for EU legislation: EUR-Lex articles as documents.


LexAPILegislationRetriever searches EU legislation by meaning and returns one document per hit, each an article or other part of an act. With as_of, a hit is the version listed for that date, or a notice when LexAPI could not establish it.

Python
from langchain_lexapi import LexAPILegislationRetriever

# The articles in the version LexAPI lists for 1 June 2019.
retriever = LexAPILegislationRetriever(k=3, as_of="2019-06-01")
for doc in retriever.invoke("right to erasure"):
    print(doc.metadata.get("cite_celex"), doc.metadata.get("article_ref"))
    print(doc.page_content)
  • page_content is the article text followed by a Source: line with the CELEX number, the article and the EUR-Lex link.
  • metadata carries the same fields: cite_celex is the act to cite. A consolidated text is labelled as such: it has no legal force, and only the act as published in the Official Journal is authentic.
  • When LexAPI could not establish a hit’s text for the date, the document is a notice with the reason, not the text, and metadata["text_withheld"] is true. Do not index those. unresolved="drop" leaves them out.
  • A search costs 5 credits; with as_of, up to 20.

The retrieval it wraps, over REST

§ 03 — Case law

CJEU case law retriever for LangChain.


LexAPICaseLawRetriever searches CJEU case law by meaning. A document’s text is the whole decision; max_chars cuts it and marks the cut.

Python
from langchain_lexapi import LexAPICaseLawRetriever

retriever = LexAPICaseLawRetriever(k=2, max_chars=4000, court="Court of Justice")
docs, report = retriever.invoke_with_report("right to be forgotten and search engines")
for doc in docs:
    print(doc.metadata.get("ecli"), doc.metadata.get("decision_date"))
print(report.units_charged, "credits charged")

invoke_with_report returns the documents and what the call cost; plain invoke returns the documents only. A case-law search costs 5 credits.

§ 04 — Agent

LangGraph agent tools.


The tools are ordinary LangChain tools. create_agent builds a LangGraph agent from them; define model first, a chat model of your choice.

The agent examples also need pip install langchain (it brings LangGraph).

Python
from langchain.agents import create_agent
from langchain_lexapi import (
    LexAPILegislationAsOfTool,
    LexAPIReadDocumentTool,
    LexAPISearchLegislationTool,
)

agent = create_agent(
    model,  # any LangChain chat model that supports tool calling
    tools=[LexAPISearchLegislationTool(), LexAPIReadDocumentTool(), LexAPILegislationAsOfTool()],
    system_prompt="Answer from EU law. Cite the CELEX number of every source you use.",
)
result = agent.invoke(
    {"messages": [{"role": "user", "content": "What did Article 17 GDPR say on 1 June 2019?"}]}
)
print(result["messages"][-1].content)

In a graph of your own, the same tools go in a ToolNode:

from langgraph.prebuilt import ToolNode
from langchain_lexapi import (
    LexAPILegislationAsOfTool,
    LexAPIReadDocumentTool,
    LexAPISearchLegislationTool,
)

tools = ToolNode([LexAPISearchLegislationTool(), LexAPIReadDocumentTool(), LexAPILegislationAsOfTool()])
ToolCreditsWhat it does
lexapi_search_legislation5; up to 20 with as_ofArticles of EU legislation by meaning, optionally the text for a date
lexapi_read_document1, 4 or 5 by sourceA document by CELEX number, or one article; within a character budget, the rest listed
lexapi_legislation_as_of1, 4 or 5 by sourceThe version of an act listed for a date, and one provision of it

A read costs 1 credit when LexAPI already holds the document, 4 or 5 when it is fetched from the source first. The as-of tool costs 1 credit when no text is fetched.

  • A failed call raises ToolException; handle_tool_error=True hands its message to the model.
  • Each tool message carries the call’s report and each passage’s metadata in its artifact, so your code can read what the call cost.
§ 05 — Scope

What the package does not do.


  • It does not call a language model, build prompts or chains, embed texts or cache results.
  • k is the number of hits asked for; fewer can come back. celex= filters the hits after the search.
  • It is a client of LexAPI, not of EUR-Lex: every call goes to the LexAPI REST API with your key and is billed like the endpoint it calls. In LlamaIndex instead: EU law in LlamaIndex.
§ 06 — FAQ

Asked & answered.

N° 01Is there a LangChain integration for EU law?+
LexAPI publishes langchain-lexapi on PyPI: a retriever over EU legislation, one over Court of Justice case law, and tools for an agent. It calls the LexAPI REST API and needs a LexAPI API key. LexAPI is not affiliated with LangChain, EUR-Lex or the Publications Office.
N° 02Does langchain-lexapi work with LangGraph?+
Yes. Its tools are LangChain tools: pass them to create_agent, which returns a LangGraph graph, or put them in a ToolNode in a graph of your own.
N° 03How does the model know which act a LangChain document comes from?+
Each document’s page_content ends with a Source: line that names the CELEX number, the article (for case law, the ECLI) and the EUR-Lex link, and its metadata carries the same fields, cite_celex among them. A consolidated text is labelled as having no legal force: cite the act as published in the Official Journal.
N° 04What does a LangChain retriever return when the text for a date is not known?+
With as_of, a hit whose text LexAPI did not establish for that date comes back as a notice with the reason instead of text, with metadata text_withheld set to true. Do not index those documents; unresolved="drop" leaves them out.
§ 07 — Next

Keep building.


  • QuickstartA first request by curl, MCP, Python and TypeScript.
  • API referenceEvery endpoint, parameter, response field and error.
  • MCP serverSetup for Claude, Cursor and VS Code, and the tool list.
  • PricingPlans, credit pools and what each call costs.

LexAPI returns source texts and their identifiers. It does not assess compliance and gives no legal advice.