Langfuse code evaluators for deterministic checks

Code evaluators score LLM output with plain Python or TypeScript rules such as JSON validity, regex and tool-call checks. This page covers setup on self-hosted Langfuse, SDK requirements and when code beats a judge model.

On this page

Code evaluators for deterministic checks in self-hosted Langfuse

Many LLM outputs have rules that never need a model to check. A response must be valid JSON, include required fields, avoid banned phrases, or call a tool with correct arguments. Code evaluators let you write these checks as Python or TypeScript functions that Langfuse runs against traces, so each result is stored as a score next to the output it describes. The core feature is part of the MIT-licensed open source version of Langfuse, which Langfuse states offers all core features and APIs without limits, so a self-hosted instance does not need an Enterprise license key for it. This section explains when to use code evaluators and what to settle before building them.

Code is the better choice when the rule has a definite answer. A JSON parse either succeeds or fails, a required field is present or missing, and a regex either matches or it does not. The same input always gets the same score, the check makes no model calls, and engineers can read the logic and reproduce a failure. Judge models remain the better choice for qualities that need interpretation, such as whether an answer is faithful to retrieved context or matches a requested tone. Use the two together: deterministic checks catch structural breakage cheaply on every trace, and judges score the qualities that require reading. Illustrative example: a support bot that must return a refund_amount field can be checked by code, while whether its explanation is courteous goes to a judge.

Before you build, confirm three things with the Langfuse documentation and your own environment. First, list the checks your team needs and confirm that each can be written as a function that reads only the trace data Langfuse passes to it. Second, confirm the version of your self-hosted instance. The Langfuse releases on GitHub page lists v4.63.0, published October 16, 2026, but your deployment may run an earlier release, so verify that code evaluators are available in it. Third, check the SDK versions your applications use, since Python SDK v5 and JS/TS SDK v6 require Langfuse v4.59.0 or later. Ask your implementation partner or Langfuse for the dispatcher setup and evaluator runtime limits in writing, because they determine where evaluator code executes on your infrastructure and who operates it.

Which checks suit code and which suit a judge

Structural checks ask whether an output has the right shape. Code is the natural fit because the rule is precise and can be run on every trace at negligible cost. A JSON parser either accepts the string or it does not, and a regular expression either matches the required format or it does not. The limit is that structure says nothing about whether the content is correct, only that it is well formed.

  • JSON validity: Parse the output and report a boolean. Schema validation adds field types, required keys and enum values, and it is usually the more useful check.
  • Regex and format: Confirm identifiers, dates, currency codes or citation markers follow a pattern. Keep patterns readable, since a clever expression is hard to review.
  • Length and forbidden content: Count characters or tokens, or scan for strings that should never appear, such as internal hostnames.
  • Where code fails: A valid JSON object can hold a wrong answer, and a regex cannot tell a true date from a plausible one.
  • Fixed inputs: Structural rules must be updated when the expected format changes, so tie them to a versioned schema.

Check that each structural rule describes a requirement someone can state in one sentence, and that a failing example is reviewed to confirm the rule is not too strict.

How a code evaluator run flows through the dispatcher

The run starts when the application or an experiment sends a trace to Langfuse Web, which stores it in ClickHouse and hands an evaluation job to the Langfuse Worker. The worker reads the trace, runs the code evaluator and writes the resulting score back to the same trace. Everything inside the dashed boundary runs in your infrastructure, so trace content never leaves it during evaluation. The hand-off between Web and Worker, and whether the evaluator executes inside the worker process, are dispatcher details to confirm against the Langfuse docs for your version before you design the sandbox.

Trace path from application to written score, with the self-hosted boundary marked.

Configuration options and when each fits

This table compares the main configuration choices for a code evaluator: score type, where the evaluation runs, observation-level versus experiment-level scope, and sampling. Read each row as a decision: the first column names the choice, and the other columns say when it fits and what it costs you. Check exact setting names and availability in the current Langfuse docs before you build, because the product changes between releases.

OptionWhen it fitsTrade-off to accept
Boolean scorePass or fail rules such as valid JSON, required tool call present, or no forbidden pattern in outputHides how close a failure was, so near-misses look the same as large errors
Numeric scoreCounts or measurable distances, such as number of missing required fields or length against a limitNeeds a threshold decided later, and averages can hide a small number of severe failures
Categorical scoreSeveral named outcomes, such as which validation step failed or which tool-call policy was violatedCategory lists must be kept stable, or trend charts split across renamed values
Python SDK evaluatorYour application and evaluation code already runs in Python, or the check depends on Python libraries such as a JSON schema validatorYour team must maintain the runtime and the SDK version alongside the platform version
TypeScript SDK evaluatorThe application stack is Node.js or TypeScript and the check reuses existing typed schemas or parsersCheck SDK compatibility with your Langfuse version, since SDK major versions can require a newer server
Observation-level evaluationChecks that apply to each production trace or observation, such as tool-call rules on live trafficRuns on real traffic, so every check adds load and needs sampling and filters to stay bounded
Experiment-level evaluationChecks run against a dataset during a test run, such as comparing a candidate prompt's outputs to expected valuesResults only reflect the dataset chosen, so coverage depends on how representative the test items are
Sampling and filtersHigh-volume traffic where a deterministic check is cheap but still adds work, or where only one route or model needs checkingUnsampled failures are invisible, so document which traffic each score covers

How to set up a code evaluator on a self-hosted instance

This sequence takes a deterministic check from code to a scored sample on your own Langfuse instance. Each step ends with a check so the platform owner, the engineer who writes the rule and the reviewer can confirm the evaluator is scoring traces before anyone relies on its results.

  1. Confirm the Langfuse and SDK versions

    The platform owner checks the running Langfuse version against the SDK versions your application and check code will use. Python SDK v5 and JS/TS SDK v6 need Langfuse v4.59.0 or later, so an instance on an older version cannot run them. For a Helm deployment with bundled data stores, the chart must be moved from v1 to v2 before Langfuse is upgraded to v4. The step is done when the instance version and both SDK versions are recorded in the change record and match.

  2. Confirm the worker processes evaluation events

    The platform owner confirms that Langfuse Worker, the container that handles asynchronous event processing, is running alongside Langfuse Web, PostgreSQL, ClickHouse, Redis or Valkey and S3-compatible blob storage. Scoring happens after a trace arrives, so a working UI alone does not show that evaluations will run. Ask the team that operates the deployment to confirm the worker is up and that its logs show a test trace being handled. The step is done when a trace sent from a test script appears in the UI and the worker logs confirm it was processed. If the worker is missing or idle, fix the deployment before writing any evaluator.

  3. Write and version the check code

    An engineer writes the deterministic check in Python or TypeScript, such as a JSON parse, a regex match or a rule confirming that a required tool call appears with valid arguments. The function reads the input and output of the trace or observation and returns a value that matches the score config defined in the next step. Keep the code in the same version control system as the application, tag each change and record the Langfuse SDK version it was tested with. The step is done when the check passes a set of hand-labeled examples in a local run, including outputs that should fail.

  4. Define the score config

    The team creates a score config in Langfuse that sets the score name, data type and allowed values, so the check's output is stored consistently. A boolean or categorical type usually fits pass or fail rules, while a numeric type fits counts such as the number of missing fields. Use one name per check and do not change its meaning later, because changing it makes older scores hard to compare. The step is done when the config appears in the project's score settings and a test score written with the SDK is accepted under it.

  5. Attach the evaluator to traces or experiments

    A project owner attaches the check to the traces or observations it should score, or to experiment runs made with the SDK experiment runner, and sets any filter that limits which items are scored. Start with a narrow filter, such as one application or one trace name, so a faulty rule cannot write scores across all traffic. Confirm which evaluator options your instance and version provide, since these change between releases. The step is done when the evaluator shows as active in the project and a new trace matching the filter receives a score.

  6. Verify a scored sample against expected results

    The reviewer opens a sample of scored traces, compares each stored score value with the expected result from the labeled examples, and checks that failures point to the right observation. The sample should include traces that should pass and traces that should fail, and the reviewer checks the score value itself, not only whether a score exists. Record each mismatch, fix the code or filter, bump the code version and repeat the sample. The step is done when the sample matches the labels with no unexplained mismatches, and the result is saved with the code version and SDK version.

SDK and runtime requirements to confirm before building

Code evaluators depend on three things lining up: the Langfuse server version, the SDK generation and the runtime that executes your checks. Confirm each one before writing the first evaluator, because a mismatch shows up as failed or missing scores rather than as a clear error.

Minimum Langfuse server version

The Python SDK v5 and the JS/TS SDK v6 both need Langfuse v4.59.0 or later on the server. Check your self-hosted version before writing any evaluator, because an older instance may not accept the scores your checks produce. If your instance runs an earlier release, plan that upgrade first, since major upgrades follow their own migration guides.

Langfuse upgrade guide

Language runtime choice

Python and TypeScript each have their own SDK generation and release cadence. Choose the language your platform team already operates, so the evaluator code shares the runtime, linting and test tooling of your other services. Confirm dispatcher support for that language on your exact Langfuse version before committing, since support for code evaluators may vary between SDKs and server releases.

Pin SDK and dependency versions

Pin the Langfuse SDK to an exact version, and pin every library your checks import, such as JSON schema validators or regex engines. SDK major versions track server requirements, so an unpinned install can pull an SDK that a given server rejects during a routine rebuild. Keep the lockfile in the same repository as the evaluator code and review it each time you upgrade Langfuse. Pinned versions keep evaluator results reproducible across environments and reruns.

Where the code runs

Decide where the check executes: in a service you already operate, in a dedicated worker, or in another environment you control. Document the path from the evaluation trigger to the score written back, and list the network access, project-scoped credentials and log locations each hop needs. The runtime location sets the network and secret scope, so confirm with the self-hosting docs how your instance dispatches evaluator work before you choose it.

Self-hosting docs

Data store versions for v4

Langfuse v4 also sets minimum versions for its data stores: PostgreSQL 15 or later and Redis 7.0 or later. Your evaluators write scores into the same stores that serve traces, so a platform that lags these minimums blocks the scores your checks depend on. Confirm the versions of your managed or bundled stores before upgrading, and read the v4 guide's advice on ClickHouse disk headroom for backfills.

Minimum ClickHouse version
25.12
v3 to v4 guide

Check the current release

The Langfuse releases page lists a newer release dated October 16, 2026 than the minimum above. Read the release notes for each version you pin, because SDK compatibility and evaluator behavior can change between releases. Record the server version and SDK versions together in your runbook, so a failed evaluator can be traced to one specific combination.

Latest listed release
4.63.0
Langfuse releases

Questions teams ask before building code evaluators

What drives the effort of writing code evaluators?

The effort depends mainly on how many checks you need, how precisely each one is defined, and how much of your data shape the checks must understand. A single JSON validity check against one output format is small. A set of tool-call rules that must read different span structures, handle missing fields and agree with your application's schema is much larger. The work includes writing the rule logic in Python or TypeScript, deciding the score name and data type each check writes, testing edge cases such as empty outputs and malformed payloads, and wiring the check into the evaluator dispatcher on your instance. Teams that already have clear output contracts usually spend less time than teams that must first agree on what a correct answer looks like. Ask any partner to break the estimate into rule design, implementation, dispatcher setup and testing, so you can see which part you are paying for.

Can our engineers build code evaluators without outside help?

Yes, if your team already writes Python or TypeScript services and can operate a self-hosted Langfuse instance. The checks themselves are ordinary code: string handling, JSON parsing, regular expressions and comparisons against the tool-call schema your application uses. The harder parts are the operational ones: running the evaluator dispatcher on your infrastructure, confirming that the SDK version you use is compatible with your Langfuse version, and keeping the scores consistent across projects. Engineers who have not operated a self-hosted deployment before often benefit from an outside review of the dispatcher setup and the first few evaluators. DeployOpen can plan and build this work as a fixed-scope engagement, with scope and deliverables agreed in writing before work starts. Your team should confirm which of these skills it has before deciding.

How long does a first code evaluator take to validate?

The time to validate a first evaluator depends on its scope, not on a fixed number. A single deterministic check that runs against a small sample of traces can be validated in a short cycle, while a set of checks covering several applications, environments and score configurations takes longer. Validation includes confirming that the evaluator fires on the right observations, that the score lands with the expected name and type, that failures are explainable to a reviewer, and that the dispatcher behaves correctly under normal load. No supplied source gives a duration for this work, so ask any partner or your own engineers to state the validation steps and the environments they will use, then compare the plan against your release schedule.

What does our team need to provide for the work?

Your team needs to provide access and decisions, not just time. The usual inputs are:

  • A self-hosted Langfuse instance in your infrastructure, with the Langfuse Web and Langfuse Worker containers running and reachable by the people doing the work.
  • Sample traces that show the real output shapes, including failure cases, so checks are built against actual data rather than assumptions.
  • A written definition of each rule, such as the required JSON keys, the allowed regular expression patterns or the tool-call sequence that counts as valid.
  • Named owners who can approve score names, score types and the projects where the evaluators run.
  • Access to your source control and deployment pipeline if the evaluator code must be versioned and released like other services.
Why are code evaluators usually cheaper to run than judge models?

Code evaluators run as deterministic logic inside your own compute, so the recurring cost is mainly the compute and storage used by your Langfuse containers and the time engineers spend maintaining the rules. A judge model adds a per-evaluation model call, which is a recurring cost tied to token usage and the model provider you choose. Code also gives repeatable results for the same input, which makes regressions easier to trace. The trade-off is coverage: code cannot judge tone, relevance or factual accuracy in the way a judge model can. When comparing quotes, ask for the one-time build cost separately from the recurring run and maintenance cost, and ask how each check scales as trace volume grows. Judge model costs depend on your provider's pricing, which you should confirm with that provider.

How do Langfuse upgrades affect our code evaluators?

Updates within a major version are described by Langfuse as non-disruptive, with database migrations applied automatically at startup. Major upgrades change more, so evaluators need checking against each release. Langfuse notes that Python SDK v5 and JS/TS SDK v6 need Langfuse v4.59.0 or later, so an evaluator written against one SDK generation may need changes before a platform upgrade. The v3 to v4 guide also moves ClickHouse to an observations-first data model, which can change how your evaluators find the data they read. Keep the evaluator code in version control, pin SDK versions, and retest every evaluator against a staging copy before upgrading production. Read the Langfuse upgrade guide before scheduling any major change.

Do code evaluators need a Langfuse Enterprise license?

Running code evaluators depends on the core features of Langfuse, which Langfuse states are available in the MIT-licensed open source version without limits. The Enterprise license key covers separate features such as project-level RBAC roles, audit logs and server-side data masking. Those features matter if your evaluator results are reviewed by people in different roles or if the traces contain sensitive data. Confirm with Langfuse which features your evaluator workflow depends on before you assume the open source version is sufficient, and record that decision in your design notes. The Langfuse license key documentation lists the features that require a key.

When should we choose a code evaluator instead of a judge model?

Choose a code evaluator when the correct answer can be stated as a rule that a program can check, such as valid JSON, a required field present, a regular expression match or a tool called in the allowed order. These checks are fast, repeatable and easy to explain to a reviewer. Choose a judge model when the quality depends on meaning, tone or relevance that a rule cannot capture. Many teams use both: code for the structural checks that must never fail silently, and judge models for the judgment-based scores. Settle this split before building, so that the rule-based checks are not stretched to cover subjective quality or the judge prompts are not used to police formats that a few lines of code could verify.

Limits to confirm in your own environment

Code evaluators run on infrastructure you operate, so several behaviors depend on the exact Langfuse version and your deployment. The cards below list what to confirm with the Langfuse docs or a test instance before you commit to a design, rather than assuming defaults carry over.

Dispatcher behavior on your version

Confirm how the evaluator dispatcher picks up and runs code evaluators on the Langfuse version you plan to run, including how it chooses which traces or observations to evaluate, the order of execution and what happens when an evaluator is edited or disabled mid-run. Test this on a staging instance with a deliberately failing evaluator. Read the release notes for the version you pin, since dispatcher behavior has changed between releases.

Langfuse upgrade guide

Execution time and resource limits

Find out the maximum run time per evaluator, the memory available to each execution, and whether a timed-out or crashed check is recorded as an error score or silently dropped. These limits decide whether a regex or JSON check on long model outputs is safe to run on every trace. Ask how the limits apply to self-hosted worker containers, which you size yourself, and whether they can be changed without a restart.

Supported languages and packages

Confirm which Python and TypeScript runtime versions the evaluator sandbox supports, and which third-party packages you can import. Check whether you can add a package such as a JSON schema validator or a parser, how it gets installed into the environment, and whether your network policy allows that installation on a locked-down host. If a check needs a library the sandbox does not provide, plan a pure-standard-library version before you start.

Behavior during worker scaling

Langfuse recommends scaling worker containers on CPU load, so confirm that an evaluator run is not duplicated, lost or scored twice when a worker is added, removed or restarted during a deployment. Ask how in-flight executions are handled on shutdown and whether scores already written are retained. Run a scale-up and scale-down test under realistic ingestion load before you rely on the results for alerting or CI gates.

Langfuse scaling guide

Sandbox isolation and secrets

Confirm what a code evaluator can reach: outbound network access, the filesystem, environment variables and any stored credentials. A check that only inspects text should not need a secret or a network call, so remove both where possible. Verify the isolation model in your own environment, because a self-hosted worker may run in a network segment with different egress rules than the vendor's default.

How DeployOpen scopes and delivers code evaluators

DeployOpen plans, builds, tests and documents Langfuse code evaluators inside your own infrastructure, including the self-hosted Langfuse deployment they run on. The work starts from a written scope that names each deterministic check, its inputs and the outputs your teams need to act on.

How we scope

  • Inventory each deterministic check, such as JSON validity, regex matches and tool-call rules, and record what pass and fail mean for your team.
  • Confirm which Langfuse version, SDK language and dispatcher setup your self-hosted instance runs before any evaluator code is written.
  • Agree the written scope in advance, including deliverables, timelines and which checks stay with a judge model instead of code.

How we build

  • Write Python or TypeScript evaluators with versioned test cases that cover valid, invalid and edge-case outputs for every rule.
  • Configure the evaluator dispatcher and worker capacity on your self-hosted Langfuse, then verify scores appear on the traces they should.
  • Test evaluators against sample traces from a non-production instance and record how each score is attached and filtered.

How we hand over

  • Deliver source code, configuration and a runbook covering how each evaluator is added, changed, disabled and rolled back.
  • Document the SDK and Langfuse version pairings your evaluators depend on, so upgrades are planned against them.
  • Walk your engineers through the score definitions, failure handling and the checks that should move to a judge model later.

How we support

  • Review evaluator behavior after Langfuse upgrades, including SDK changes that affect how code evaluators run.
  • Add or adjust checks as your tool schemas and output formats change, under a retainer if you want continuous support.
  • Ongoing support, upgrades and continuous testing are available as retainers, with scope confirmed in writing.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.