Scorers
A scorer defines what you measure and what counts as a pass. Use item scorers to check individual answers and an experiment scorer to compare whole runs.
Add more scores
Use a separate scorer for each thing you want to measure, such as correctness, relevance, or whether the agent selected the right tool.
| Scorer type | Result value | Example |
|---|---|---|
| Boolean | true or false | Did the agent complete the task correctly? |
| Numeric | A number | How relevant is the answer, from zero to five? |
| Categorical | A list of category keys | Which failure types occurred, such as ["wrong_tool"]? |
Create scorers with the SDK or in Scorers. Each result references a fixed scorer version, so configuration changes don't reinterpret earlier results.
With the SDK, use a project secret API key or a personal API key. Grant llm_analytics:read to read scorers and versions or validate a composite formula. Grant llm_analytics:write to create or update scorers and publish versions.
For each additional reported score, use the same item and the new scorer's version ID. Call upload_result() in Python, uploadResult() in TypeScript, or UploadResult() in Go. The expected result count includes all reported and calculated item results.
Use reasoning to explain a score. Set application_trace_id / applicationTraceId on the item to link it to an AI Observability trace.
Failed checks and evaluator errors
Use value=False / value: false for a failed check. The default status, ok, means the evaluator produced a score, not that the item passed.
If the evaluator can't produce a score, upload status="error" / status: "error", omit value, and include an error_message / errorMessage. Use skipped for a check you didn't run, or not_applicable when a scorer doesn't apply to an item.
Combine scores with a composite scorer
An item composite combines reported scores for one item into a boolean, numeric, or categorical result.
For the support-agent example, Support task passed requires both Correct tool and Correct arguments to pass. Three of the six cases pass both checks, giving a 50% pass rate.
Create the composite
Use the quickstart's SDK and environment variables and the two scorers you created there. Save this as create_composite.py or create_composite.mts and run it once. For Go, create a composite directory next to go.mod, save the example as composite/main.go, and run go run ./composite.
Save the printed scorer ID:
You can also create this scorer in Scorers. Choose Composite formula and Boolean, add the two input scorers, and set their Formula name fields to tool_correct and arguments_correct. Use tool_correct and arguments_correct as the formula and True means pass as the passing value.
Each input uses a fixed scorer version. New input versions don't update the composite automatically. Changing its formula or inputs creates a new composite version; existing results stay unchanged.
Request a calculation for each item
Upload the reported inputs and a calculation request together for each item. Creating the scorer alone doesn't calculate results.
In support_eval.py or support_eval.mts, add EvaluationResult to the SDK imports. Keep the agent, evaluator, and cases, then replace the client block below them with this code. In baseline/main.go, replace the runExperiment function with the Go example. Each example uses the input versions saved in the composite.
Run the updated script with the quickstart command. For a composite result, send only the item, scorer version, and calculate set to true. PostHog calculates the value. Check the status and error code on each returned result. An upload can succeed while a calculation fails.
This run expects 18 results: twelve reported and six composite. Accepted errors and skipped results count toward the total. Start a new experiment to test another composite version; completed runs can't accept new results.
Sending the inputs and calculation together works with the quickstart's permissions, including on retries. To reuse previously uploaded inputs, also grant evaluation:read and llm_analytics:read. For larger batches, keep each item's results together so the SDK can send them in one request.
Open the experiment to see Support task passed alongside the two reported scorers. Items without a calculation request show Not requested and don't affect its pass rate.
Write formulas
These formulas use the two boolean inputs from the support-agent example:
| Output | Formula | Meaning |
|---|---|---|
| Boolean | tool_correct and arguments_correct | Pass only when both checks are true. |
| Numeric | (number(tool_correct) + number(arguments_correct)) / 2 | Return 0, 0.5, or 1 for each item. |
| Categorical | "pass" if tool_correct and arguments_correct else "fail" | Return a category key configured on the composite. |
Formulas read raw input values. number(True) is 1 and number(False) is 0, even if an input scorer treats true as a failure. For categorical inputs, test category keys with expressions such as "helpful" in relevance.
In the UI, the formula editor suggests a formula from the output type and inputs' passing rules. Manual edits stay unchanged when you edit inputs. Click Use default formula to restore the suggestion.
You can use arithmetic (+, -, *, /), comparisons, and, or, not, conditional expressions, and the number, min, max, and abs functions. Each item formula can reference up to 16 reported scorer versions. Every selected input must appear in the formula.
Handle missing inputs and calculation errors
If a pinned input result is missing, PostHog rejects the entire upload request. Include that input for the same item and version when you retry.
If an input has status error, skipped, or not_applicable, the composite inherits that status without a value. If several statuses apply, the order is error, then skipped, then not_applicable. Input errors use the code composite_input_error.
A calculation error, such as division by zero or a value outside the composite's configured bounds, produces an error result with code composite_formula_error. Valid reported inputs in the same request are still saved. These errors don't enter the composite's mean or pass rate.
Score a whole experiment
Suppose you're comparing two versions of the quickstart's support agent. Choosing the right tool matters, but calling it with the wrong order ID could refund the wrong customer. You can give Correct arguments 60 points and Correct tool 40 points, then compare runs on a 100-point scale.
- Open Support agent baseline in Experiments and click Set up experiment score.
- Name the scorer Support quality. Choose a numeric result from 0 to 100. Add Correct arguments and Correct tool as inputs, select Pass rate for each, and give them the formula names
argsandtool. - Enter
60 * args + 40 * tooland click Preview on this experiment. Four of six cases passed the argument check and five passed the tool check, so the score is about 73 out of 100. - Under Apply to suite keys, select
support-agentand save. Run the quickstart again. PostHog now scores completed runs for that suite in this environment. Your script still uploads twelve item results.
Choose what goes into the score
Each input uses results from an item scorer, including an item composite. Only results with status ok count, whether the check passed or failed. Rates range from 0 to 1.
| Statistic | What it measures |
|---|---|
pass_rate | Fraction that passed the scorer's passing rule. |
mean | Average value of a numeric scorer. |
true_rate | Fraction of boolean results that were true, even if true means failure. |
category_rate | Fraction of categorical results containing the category you select. |
By default, each input uses the one scorer version that produced scores in that run (run). If several versions produced scores, choose Exact version (exact) to use just one, or Combine versions (combine) to pool their scored items. If two versions scored the same item, PostHog leaves the pooled score blank.
Set up the same scorer with the SDK
These examples require the experiment scorer API for Python, TypeScript, or Go. If your SDK doesn't have it yet, use the setup in PostHog above.
Run this once, after looking up the two item scorers as in the quickstart.
To use this formula for one run regardless of the suite default, pass its version ID when you create the experiment.
| Python | TypeScript | Go (evaluations.Fields) |
|---|---|---|
experiment_scorer_version_id=quality.current_version_id | experimentScorerVersionId: quality.currentVersionId | "experiment_scorer_version_id": quality.CurrentVersionID |





