# Chalk Compute Reference: Scorers
source: https://docs.chalk.ai/compute-docs#section-scorers

Built-in scorers for evaluations, in `chalkcompute.scorers`.

Calling a built-in deploys it and returns a handle to pass to `Evaluation.create`. [`sql`](https://docs.chalk.ai/compute-docs#sql) is the exception: it builds a [`SqlExpression`](https://docs.chalk.ai/compute-docs#SqlExpression) evaluated in the run's query, so nothing is deployed.

## `contains(name, inputs, mode, case_insensitive, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#contains

Deploy a scorer that looks for expected substrings in a column.

The reference column holds one substring, or a JSON array of them. `mode` scores them together: `"all"` demands every one, `"any"` one of them, and `"fraction"` gives the share that appeared. Which ones matched and which were missing are recorded as metadata.

## `embedding_similarity(name, inputs, model, base_url, api_key, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#embedding_similarity

Deploy a scorer that grades two columns by how close their meanings are.

Both columns are embedded with `model` and scored by cosine similarity, clipped into `[0, 1]`, with the raw cosine recorded as metadata. This catches an answer that is right but worded differently, which the string scorers mark wrong. `base_url` and `api_key` name the endpoint and the Secret holding its key, as they do for [`llm_judge`](https://docs.chalk.ai/compute-docs#llm_judge).

## `exact_match(name, inputs, case_insensitive, strip, normalize_whitespace, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#exact_match

Deploy a scorer that gives 1.0 when two columns hold the same text.

`inputs` names the candidate column and then the column it is compared against. `strip` trims each side, `normalize_whitespace` collapses runs of whitespace instead, and `case_insensitive` folds case. The metadata records whether the two matched.

## `json_match(name, inputs, paths, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#json_match

Deploy a scorer that compares two columns as JSON documents.

Without `paths` the whole documents must be equal, so object key order does not matter but list order does. With `paths` (dotted, as in `"user.id"` or `"items.0.sku"`) the score is the share of those paths whose values agree. Either way the paths or keys that differed are recorded as metadata, and a column that does not parse scores 0.0. Values are compared as JSON, so `true` never passes for `1`.

## `json_valid(name, inputs, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#json_valid

Deploy a scorer that gives 1.0 when a column parses as JSON.

Useful on its own for a task asked to answer in JSON. The parser's complaint is recorded as metadata when it does not parse. `NaN` and `Infinity` are rejected, as the JSON grammar has no place for them.

## `levenshtein(name, inputs, case_insensitive, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#levenshtein

Deploy a scorer that grades two columns by their edit distance.

The score is `1 - distance / len(longer)`, so identical text scores 1.0 and text sharing nothing scores 0.0. The edit distance itself is recorded as metadata. This is the same quantity as `F.levenshtein_distance`, normalized into a score.

## `llm_judge(response_model, model, name, instructions, inputs, prompt_fn, parse_fn, base_url, api_key, completion_kwargs, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#llm_judge

Deploy an LLM judge described by a dataclass or Pydantic model.

`response_model` needs a `score` field, which becomes the scorer's score; its other fields are recorded as row metadata. A reply that fails validation fails the row.

`inputs` are the dataset columns to grade (`output` is the task's). Naming `trace` among them hands the judge the row's `Trace`, rendered into the prompt with `transcript`, or [`None`](https://docs.python.org/3/library/constants.html#None) for a row that recorded no telemetry. The default prompt fails the row if raw trace content was externalized but not loaded, or was omitted/truncated during recording. `prompt_fn(response_model, **inputs)` replaces the prompt and receives that same handle; `parse_fn` replaces structured outputs. With neither `base_url` nor `api_key` the judge calls Chalk's AI router as the environment itself, so no provider key is needed; `base_url` takes any other OpenAI-compatible URL and `api_key` a Secret read in the pod. `completion_kwargs` (say `{"temperature": 0, "max_tokens": 400}`) are sent with every request. `name` defaults to the model class in kebab case; other keywords go to `function`.

## `numeric_close(name, inputs, tolerance, relative, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#numeric_close

Deploy a scorer that compares two columns as numbers.

With a `tolerance` the score is 1.0 or 0.0 depending on whether the two are within it, taken as a share of the larger value when `relative`. Without one the score falls off with the gap between them, as `1 - gap / max(abs(a), abs(b))`. The signed difference is recorded as metadata. A column that does not parse as a finite number scores 0.0, which covers `inf` and `nan` as well as ordinary text.

## `regex_match(pattern, name, inputs, flags, full_match, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#regex_match

Deploy a scorer that gives 1.0 when a column matches `pattern`.

`full_match` requires the pattern to cover the whole column instead of appearing anywhere in it. The matched text and any named groups are recorded as metadata, so a pattern can also pull a value out of the row. An unusable pattern is rejected here rather than on every row.

## `sql(name, expression)`
source: https://docs.chalk.ai/compute-docs#sql

Score rows with a Chalk SQL expression you write yourself.

`expression` is a select item over the evaluation's own columns: every dataset column by name, plus `output`, the task's result for the row. It must yield a number. Nothing is deployed; `name` labels the result column and the row in the compare table.

## `string_similarity(method, name, inputs, case_insensitive, image, function_kwargs)`
source: https://docs.chalk.ai/compute-docs#string_similarity

Deploy a scorer that grades two columns by string similarity.

[`method`](https://docs.chalk.ai/compute-docs#method) picks the measure: `"jaro_winkler"`, `"jaccard"`, `"token_set"`, `"token_sort"`, `"partial"`, or `"sequence"`. Each is the same quantity as the `chalk.functions` of that name, expressed as a similarity in `[0, 1]`, and the raw value is recorded as metadata. Two empty columns score 1.0.

## `SqlExpression`
source: https://docs.chalk.ai/compute-docs#SqlExpression

Class

A scorer whose score is a Chalk SQL expression, evaluated in the run's query.

The expression is a select item over the evaluation's own columns: every dataset column by name, plus `output`, the task's result for the row. It must yield a number, and unlike a function scorer it deploys nothing and carries no metadata.

**Attributes**

- `name`: `str`
- `expression`: `str`
