Skip to main content

langchain-levanto

Levanto for LangChain: Sage decisions and extraction, and Levanto's LLMs.

pip install langchain-levanto

It reads your key from LEVANTO_API_KEY.

Decisions

LevantoDecisionModel is a LangChain decision model. It answers yes/no (Noul), Choice and Score questions about text, JSON, chat messages and images, with full probabilities.

from langchain_core.decisions import Choice, Noul, Score
from langchain_levanto import LevantoDecisionModel

sage = LevantoDecisionModel()
response = sage.invoke({
    "state": "I was charged twice. Please refund the duplicate today.",
    "questions": {
        "refund": Noul(instructions="Is the customer asking for money back?"),
        "team": Choice(
            instructions="Which team should handle this?",
            criteria={"billing": "Charges and refunds", "technical": "Bugs and outages"},
        ),
        "urgency": Score(instructions="How urgent is it?", criteria=["Can wait", "This week", "Today"]),
    },
})

response.nouls["refund"].noul      # 0.996
response.choices["team"].choice    # "billing"
response.scores["urgency"].score   # 1.99, from 0 to 2

Options: reasoning ("off", "auto", "on"), grounding, timeout (15 s by default, 60 s with reasoning), max_retries. Box questions aren't supported.

Images go in a message as LangChain image blocks (PNG, JPEG or WebP, base64): HumanMessage(content=[{"type": "text", "text": "..."}, {"type": "image", "base64": data, "mime_type": "image/png"}]). Sage reads one image per call, the last one. With an image, a choice takes up to 20 options and a score up to 10 levels; reasoning and grounding work on text only.

Extraction

from langchain_levanto import LevantoExtractTool

invoices = LevantoExtractTool(fields={
    "vendor": "the company issuing the invoice",
    "total": {"type": "money"},
    "due_date": {"type": "date"},
})
invoices.extract(invoice_text)["values"]
# {"vendor": "Nordlicht GmbH", "total": {"amount": 540.0, "currency": "EUR"}, "due_date": "2026-11-21"}

It's a LangChain tool, so an agent can call it: create_agent(model, tools=[invoices]). Without fields, the agent picks the fields on each call. A value is None when the document doesn't state it. Types: text, integer, decimal, money, date, time, datetime, duration; a one-item list (["a product billed"]) returns every mention.

Rerank

from langchain_core.documents import Document
from langchain_levanto import LevantoReranker

docs = [Document("Bananas are yellow."), Document("Paris is the capital of France."), Document("Rome is in Italy.")]
best = LevantoReranker(top_n=1).compress_documents(docs, "What is the capital of France?")
best[0].page_content  # "Paris is the capital of France."

It sorts 2 to 120 documents per call, keeps top_n (3 by default, None for all) and sets metadata["rank"]. Use it as the base_compressor of a ContextualCompressionRetriever.

Decide tool

LevantoDecideTool lets an agent ask Sage yes/no, choice, scale, tags and sort questions: create_agent(model, tools=[LevantoDecideTool()]).

from langchain_levanto import LevantoDecideTool

LevantoDecideTool().invoke({
    "kind": "tags",
    "instructions": "Which topics does it raise?",
    "content": "I was charged twice and the app crashes.",
    "tags": ["billing", "bug", "shipping"],
})
# '{"tags": {"billing": 1.0, "bug": 1.0, "shipping": 0.0}}'

Guard and route agents

LangChain's agent middleware (pip install langchain) takes any decision model.

from langchain.agents import create_agent
from langchain.agents.middleware import AutoModeMiddleware

# Sage blocks risky tool calls the user didn't ask for.
agent = create_agent(
    model,
    tools=[read_file, delete_file],
    middleware=[AutoModeMiddleware(tools=[delete_file], classifier=LevantoDecisionModel())],
)

ModelRouterMiddleware(choices=..., instructions=..., classifier=LevantoDecisionModel()) picks a model per run. Both work on conversations with images and tool calls.

LLMs

from langchain_levanto import ChatLevanto

llm = ChatLevanto(target="economy")   # model="auto" lets the router pick
reply = llm.invoke("Summarize this ticket in one sentence: ...")
reply.response_metadata["model_name"]  # the model that answered

ChatLevanto is ChatOpenAI pointed at https://api.levanto.ai/v1: streaming, tools and with_structured_output work as usual. It never reads OPENAI_API_KEY.

Development

uv venv && uv pip install -e . --group test
pytest tests/unit_tests
LEVANTO_API_KEY=... pytest -m live tests/integration_tests

Docs: https://docs.levanto.ai/integrations/langchain

Metadata

Release files for langchain-levanto 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-levanto 0.3.0
File Size Uploaded Provenance Actions
langchain_levanto-0.3.0.tar.gz 24.5 kB With provenance Details for langchain_levanto-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-levanto 0.3.0
File Interpreter ABI Platform Actions
langchain_levanto-0.3.0-py3-none-any.whl Python 3 none any Details for langchain_levanto-0.3.0-py3-none-any.whl

Total release size: 46.1 kB

Release files / langchain_levanto-0.3.0.tar.gz

Download URL langchain_levanto-0.3.0.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a4e035b7790394ceb16a3011bc1e914af4f0bd2116a6651d0b0dac983343004d
BLAKE2b-256 checksum
How to use checksums
a6a37c1b85c95d153933b85219a0fb9a5419944160aba62fda24e5e70f708b93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / langchain_levanto-0.3.0-py3-none-any.whl

Download URL langchain_levanto-0.3.0-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0a30ffab1d277156bacd653daa35725551752a4be12cab441b755eb47686da7
BLAKE2b-256 checksum
How to use checksums
f6fbb8b4d7930f94f14f36dadb299c64e298161b7c5b66dc2c213f39dcd1c70e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for langchain-levanto 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for langchain_levanto-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page