Skip to main content

Lanternfish Python SDK

Record what your AI agent does: its LLM calls, its own steps, the decisions it makes and the release it runs on. Lanternfish compares those runs over time and tells you what changed.

Built on OpenTelemetry. Works next to an existing OpenTelemetry or Logfire setup.

Install

pip install "lanternfish[openai]"

Use the extra for each provider you call: openai, anthropic, gemini, groq, langchain, crewai, llamaindex, or all. Requires Python 3.11+.

Start

export LANTERNFISH_API_KEY="lfsk_..."            # Settings → API keys
export LANTERNFISH_ENDPOINT="https://your-lanternfish-endpoint"
import lanternfish

lanternfish.instrument(agent="travel-agent")

From here on, calls to installed providers are recorded. The SDK never picks a destination by itself: without an endpoint it stops with an error that says what to set.

Record your own steps and decisions

import lanternfish

@lanternfish.trace                                  # records arguments; capture_args=False for private data
def search_flights(destination: str) -> list[str]:
    ...

with lanternfish.set_user("user_42", session_id="sess_9"):   # removed again when the block ends
    with lanternfish.span("book-trip"):
        options = search_flights("Lisbon")
        with lanternfish.reasoning(name="pick_flight") as r:
            r.consider_option("KLM 1724", score=0.8, reason="Arrives before the meeting")
            r.decide("KLM 1724", confidence=0.8, reason="Arrives before the meeting")

A step that raises is marked failed, with the exception type and message.

Releases

Every span carries the release it ran on: release= if you pass it, otherwise LANTERNFISH_RELEASE, otherwise the commit your CI or host exposes (GITHUB_SHA, VERCEL_GIT_COMMIT_SHA, RENDER_GIT_COMMIT, …). To mark the moment a release went live, call this from your deploy step:

lanternfish.record_deployment("v1.8.2", metadata={"commit": "a1b2c3d", "environment": "production"})

Score quality

Give a run a quality score from 0 to 1 (1 = good) while it runs. The release verdict compares it like duration, success and cost:

with lanternfish.span("answer"):
    answer = agent.run(question)
    lanternfish.score("correct", answer == expected)   # True/False count as 1/0
    lanternfish.score("helpful", 0.8)

Names use lowercase letters, digits and _. Outside a run, or with a value outside 0–1, nothing is recorded and a warning is logged; your code never gets an exception.

Release verdict: stop a deploy that regressed

Lanternfish compares a release with the one before it: run duration, success rate and cost per run, plus how the agent uses each tool (how many runs call it, how many times per run). The decision is Block (regressed), Review (tool use changed), Not enough data (too few runs to rule out a regression yet; the verdict says how many are needed) or Ship, and every finding states both sides:

Block: v1.8.2 regressed against v1.8.1.
  - Success rate is down 18%: 80.0% vs 98.0% in v1.8.1.
  - search_flights is called 2.3 times per run, 1.1 in v1.8.1.
Based on 212 runs of v1.8.2 vs 1,840 runs of v1.8.1.

Gate a deploy on it from CI, after the canary has served traffic. The command exits 1 when the release regressed:

lanternfish verdict --release v1.8.2                       # gate on quality regressions
lanternfish verdict --release v1.8.2 --fail-on changed     # also on behavior changes
lanternfish verdict --release v1.8.2 --allow-insufficient  # let it through when there are not enough runs yet
lanternfish verdict --model gpt-4.1 --environment ci       # a model switch, compared with the model before it

A model switch needs no release tag: the model comes from the LLM calls the SDK records. From Python: lanternfish.get_model_verdict("gpt-4.1", environment="ci").

Prompts that change without a deploy: run the agent inside with lanternfish.set_prompt_version("support-v3"):. A new version is a change of its own: lanternfish verdict --prompt support-v3 or lanternfish.get_prompt_verdict("support-v3").

Same cases on both sides. Run your CI suite with each input inside with lanternfish.set_case(case_id): (TypeScript: withCase). When both sides ran the same cases, the verdict compares each case with itself (McNemar for success, paired tests for duration, cost and scores). It needs fewer runs to rule out a regression and counts the cases that passed before and fail now. Tool use is judged only without pairing.

for case in load_cases("tests/agent_cases.jsonl"):
    with lanternfish.set_case(case["id"]):
        run_agent(case["input"])

Exit codes: 0 Ship (Review too, unless --fail-on changed), 1 Block, 2 no verdict (unknown release, rejected key, API unreachable), 3 not enough runs to rule out a regression yet. The first release has nothing to compare with and passes. From Python: lanternfish.get_verdict("v1.8.2").regressed. The verdict endpoint accepts the project API key and returns only aggregate numbers and tool names, never run content. The dashboard shows the same verdict under Releases.

Options

instrument() argument If omitted
api_key LANTERNFISH_API_KEY Project API key, sent only in the x-api-key header
endpoint LANTERNFISH_ENDPOINT Your Lanternfish API base URL
agent — Agent name on every run
release LANTERNFISH_RELEASE or CI commit Version of the running code
environment LANTERNFISH_ENVIRONMENT For example production
include [] Also record "http", "sql", "redis" calls
capture_content True Record prompt and completion text of LLM calls

What is recorded

  • LLM calls: model, tokens, duration, errors and, unless capture_content=False, the prompt and completion text.
  • HTTP (only with include=["http"]): method, host, path and status. Never bodies, headers or query strings.
  • SQL (only with include=["sql"]): the statement with literals replaced by ?. Never parameter values.

Short scripts and serverless

Spans are sent in the background in batches. Call lanternfish.flush() before a short script or a serverless handler returns; lanternfish.shutdown() runs on process exit by itself.

Troubleshooting

import logging
logging.basicConfig(level="INFO")

The lanternfish logger names the endpoint, lists the integrations it turned on, and logs every rejected batch with the reason (invalid key, plan limit reached, endpoint unreachable). Sending never raises into your code; a temporary error is retried once.

License

MIT

Metadata

Release files for lanternfish 0.5.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 lanternfish 0.5.0
File Size Uploaded Provenance Actions
lanternfish-0.5.0.tar.gz 53.6 kB With provenance Details for lanternfish-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lanternfish 0.5.0
File Interpreter ABI Platform Actions
lanternfish-0.5.0-py3-none-any.whl Python 3 none any Details for lanternfish-0.5.0-py3-none-any.whl

Total release size: 109.2 kB

Release files / lanternfish-0.5.0.tar.gz

Download URL lanternfish-0.5.0.tar.gz
Size 53.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a0473cd625139eb83199aaafc9e17120d319511ebb89ec170fbbbe53b0a1798a
BLAKE2b-256 checksum
How to use checksums
b5daa09d1ee55ae4024c5ae679ea82e690572aa030109d25991fb070db421574
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 13, 2026.

Transparency log

Release files / lanternfish-0.5.0-py3-none-any.whl

Download URL lanternfish-0.5.0-py3-none-any.whl
Size 55.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1639cfaf9d26c194e0729c385838045367d8947a51bc9f01d60e04b5d8ecf7d
BLAKE2b-256 checksum
How to use checksums
344e3bd72b9cf0f036be33c945af496f6c36b3b047e7b19cc092c1005fdc544c
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 13, 2026.

Transparency log

Security for lanternfish 0.5.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 lanternfish-0.5.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 13, 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