Metadata-Version: 2.4
Name: langfuse-neomundi
Version: 0.1.1
Summary: Write NeoMundi measurements back into Langfuse as scores on the trace
Author-email: Sebastien FAVRE <sebastien@neomundi.org>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/neomundi-io/neomundi-integrations/tree/main/integrations/langfuse
Project-URL: Repository, https://github.com/neomundi-io/neomundi-integrations
Project-URL: Documentation, https://github.com/neomundi-io/neomundi-integrations/tree/main/integrations/langfuse#readme
Project-URL: Changelog, https://github.com/neomundi-io/neomundi-integrations/blob/main/integrations/langfuse/CHANGELOG.md
Project-URL: Issues, https://github.com/neomundi-io/neomundi-integrations/issues
Keywords: langfuse,neomundi,ai-governance,llm-measurement,observability
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: System :: Monitoring
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: langfuse<6.0,>=5.2.0
Requires-Dist: neomundi<3.0,>=2.1.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Provides-Extra: examples
Provides-Extra: notebook
Requires-Dist: nbformat>=5.9; extra == "notebook"
Requires-Dist: nbclient>=0.9; extra == "notebook"
Requires-Dist: ipykernel>=6.29; extra == "notebook"

<div align="center">

[![English](https://img.shields.io/badge/EN-English-2563eb?style=flat-square)](README.md) · [![Français](https://img.shields.io/badge/FR-Fran%C3%A7ais-6b7280?style=flat-square)](README_FR.md)

# Langfuse × NeoMundi

> 🟢 **New here? Start with [Getting Started — From Integration to Verifiable Evidence](https://github.com/neomundi-io/neomundi-integrations/blob/main/GETTING_STARTED.md).** It is the **single source of truth** for the whole path: exact versions, executable commands, measured outputs, the common errors — and 🔴 **which steps are still blocked, and why**.

**NeoMundi's signed behavioural measurement, as scores on the Langfuse trace you already have open.**

**[Quickstart](#quickstart)** · **[What it refuses to do](#refusals)** · **[Notebook](notebooks/quickstart.ipynb)** · **[Limitations](LIMITATIONS.md)** · **[Cost](#what-it-costs)**

</div>

---

> **Evidence level E2.** Two real measurements on 2026-11-26, re-read from
> the NeoMundi API as persisted, **and all six scores re-read from the
> Langfuse server** on both traces. See
> [LIMITATIONS.md §6](LIMITATIONS.md#6-evidence-level-e2--and-what-it-does-not-cover).

## What this is

A **bridge**, not a second observer. Langfuse keeps the trace; NeoMundi
measures the interaction; `NeoMundiLangfuseBridge` writes the measurement's
signals onto that trace as Langfuse scores, with the NeoMundi `request_id`
in each score's metadata so you can go from the trace to the signed record.

It drives the `neomundi` SDK's result types and Langfuse's own
`create_score`. It reimplements neither, measures nothing, and never
contacts the NeoMundi API.

## What it is not

- **Not an evaluator.** It transports measurements; it does not interpret them.
- **Not a tracer.** Langfuse traces. This only adds scores to its traces.
- **Not a truth checker.** NeoMundi verifies integrity and authenticity, not whether an answer was true.

## Install

```bash
pip install langfuse-neomundi
```

Python ≥ 3.11. Depends on `langfuse>=5.2.0,<6.0` and `neomundi>=2.1.0,<3.0`.


🔴 **`pip install` does not ship `examples/`, `notebooks/` or `evidence/`.** Measured on 2026-12-01 against the eight published wheels: each ships its package and its metadata, and **none** carries those directories. They live in the repository — [`integrations/langfuse/`](https://github.com/neomundi-io/neomundi-integrations/tree/main/integrations/langfuse) — so every path this page states relative to them is a repository path, not a file your install contains.
## Quickstart

⚠ **A wiring sketch, not a runnable program.** Measured on a bare `pip install langfuse-neomundi`: the first block raises `NameError` on `NeoMundiLangfuseBridge`, which it does not import, and the complete block below refuses without a real key — the SDK checks the key's format locally, which is deliberate. **The block that runs as published is just below**, and the fuller example is [`examples/01_offline_bridge.py`](https://github.com/neomundi-io/neomundi-integrations/blob/main/integrations/langfuse/examples/01_offline_bridge.py) — 🔴 **in the repository, not in the wheel.**

```python
bridge = NeoMundiLangfuseBridge(langfuse)  # your existing Langfuse client
outcome = bridge.write(trace.close())  # a neomundi TraceRecord or GovernResult
print(outcome.status, outcome.signals_written)
```

### Runnable as published — no key, no provider, no network

🟢 **Needs nothing but `pip install langfuse-neomundi`.** `dry_run=True` plans the scores and writes none, so no request reaches Langfuse and no NeoMundi call is made.

🔴 **What it prints is the refusal, and that is the demonstration.** One score is planned — the measurement's own status — and **five signals are withheld, each with its reason**. A bridge that invented a `stability_score` from a record that carries none would be worse than one that writes nothing.

```python
from langfuse import Langfuse
from neomundi import TraceRecord

from langfuse_neomundi import NeoMundiLangfuseBridge

# A real Langfuse client, pointed at nowhere: dry_run writes nothing, so no
# request is ever made. Replace the keys and the host with yours to write.
langfuse = Langfuse(
    public_key="pk-lf-not-a-real-key",
    secret_key="sk-lf-not-a-real-key",
    host="https://example.invalid",
)

# The record a NeoMundi layer hands you after a measured call. Here it is built
# by hand so the block needs no key and no NeoMundi call.
record = TraceRecord(
    client_trace_id="quickstart-0001",
    outcome="not_submitted_local_only",
    token_count=14,
    model_name="stub-model",
    latency_ms=12.5,
    submitted=False,
)

bridge = NeoMundiLangfuseBridge(langfuse, dry_run=True)  # nothing is written
written = bridge.write(record, trace_id="0" * 32)

print("status          :", written.status)
print("written         :", ", ".join(written.signals_written) or "(none)")
print("planned         :", ", ".join(f"{s.name}={s.value}" for s in written.scores) or "(none)")
print("withheld, and why:")
for name, why in written.signals_withheld.items():
    print(f"  {name:<28} {why}")
```

It prints exactly this:

```
status          : dry_run
written         : (none)
planned         : neomundi.measurement=not_submitted
withheld, and why:
  stability_score              not submitted: nothing was measured
  coherence_score              not submitted: nothing was measured
  factual_hallucination_score  not submitted: nothing was measured
  semantic_instability_score   not submitted: nothing was measured
  semantic_risk                not submitted: nothing was measured
```

### Where a real key comes from

**Ask for one at <https://neomundi.io/contact-us/>** — verified reachable, and
the only route this page states. ⚠ It is **not** a claim that no other route
exists; it is the one we can point you to today.

🟢 **You do not need one to evaluate this package.** The offline test suite
needs no credential, and the evidence committed in `evidence/` can be checked
without an account.


In context, inside a Langfuse observation:

```python
from langfuse import get_client
from neomundi import NeoMundiClient
from langfuse_neomundi import NeoMundiLangfuseBridge

langfuse = get_client()
neomundi = NeoMundiClient(api_key=..., base_url="https://api.neomundi.io")
bridge = NeoMundiLangfuseBridge(langfuse)

with langfuse.start_as_current_observation(name="answer"):
    with neomundi.trace(model_name="my-model") as trace:
        answer = call_my_llm(question)
        trace.record(prompt=question, response=answer, token_count=usage.total_tokens)
    bridge.write(trace.close())  # attaches to the active trace
```

What lands on the trace (exact names, measured offline):

| Score | Type | Written when |
|---|---|---|
| `neomundi.stability_score` | NUMERIC | the server declared it measured |
| `neomundi.coherence_score` | NUMERIC | idem |
| `neomundi.factual_hallucination_score` | NUMERIC | idem |
| `neomundi.semantic_instability_score` | NUMERIC | idem |
| `neomundi.semantic_risk` | NUMERIC | idem |
| `neomundi.measurement` | CATEGORICAL | always: `complete`, `partial`, `not_attempted`, `unknown`, `not_submitted`, `submitted_no_result` |

Each score's metadata carries `request_id`, `measurement_version` and the
evaluator provenance. The summary lists what was withheld and why.

**With `langchain-neomundi`:** pass `bridge.as_outcome_callback()` as the
handler's `on_outcome`. Only the summary is written that way — see
[LIMITATIONS.md §3](LIMITATIONS.md#3-through-langchain-neomundi-only-the-summary-is-written).

## Refusals

| Situation | Status | What reaches Langfuse |
|---|---|---|
| A signal not declared measured (even with a conventional value) | `queued` | no score for it; listed in the summary |
| No `trace_id` and no active Langfuse trace | `not_written_no_trace` | nothing |
| The measurement was not submitted | `queued` | the summary only, `not_submitted` |
| The input is not a NeoMundi measurement | `not_written_unsupported_input` | nothing |
| `dry_run=True` | `dry_run` | nothing; scores returned on the outcome |
| The bridge or the Langfuse client raises | `not_written_internal_error` | nothing; the exception type, never its message |

🔴 **`queued` means handed to Langfuse, not delivered.** Langfuse drops
scores on an API error without raising. See
[LIMITATIONS.md §1](LIMITATIONS.md#1-queued-is-not-a-delivery-receipt).

## What it costs

The bridge **bills nothing**: it never contacts NeoMundi. The measurement
it carries was billed when it was submitted — 0.030 CHF per observation —
so the cost control is wherever you measure (`sample_rate` in
`langchain-neomundi`, or your own decision to call `client.trace()`).

`dry_run=True` computes every score and hands nothing to Langfuse, so you
can wire the bridge up and read what it would write before enabling it.

## Honest status

| | |
|---|---|
| Offline test suite | 33 tests, plus 2 composition tests run when `langchain-neomundi` is installed |
| Real execution | **E2** — 2 observations, 2 re-read as persisted, 6/6 scores read back from Langfuse, 0.06 CHF (2026-11-26) |
| Maturity | beta |

Read [LIMITATIONS.md](LIMITATIONS.md) before drawing a conclusion from any score.

## Running the tests

```bash
cd integrations/langfuse
python -m pip install -e ".[dev]"
pytest -q
```

Offline, no key, no cost. The four Langfuse-failure tests take a few
seconds each, because Langfuse really does retry.

## License

Apache-2.0. See [LICENSE](../../LICENSE).
