# Specifications

A **specification** steers benchmark generation — which kinds of test cases a benchmark contains and in what proportions. It is one of the two forms of **guidance** a benchmark can be generated from; the other is a set of seed examples, documented in [More Like This](more-like-this.md). It states the overall scenario shared by every case and declares categories of variation, each with weighted labels that shape the mix of generated cases.

A specification is authored either in the specification editor in the UI or as YAML, through the CLI or API. This page documents the YAML form, and the field names below are its keys. The editor surfaces only the common fields, so a field marked *YAML only* can be set only outside the UI.

For *why* specifications are structured this way and how they fit into benchmark generation, see [Overview](../system-overview.md#specifications-controlling-the-mix). For step-by-step authoring instructions, see the [Specifications UI Guide](../ui-guide/specifications.md).

Specifications appear in two forms, kept distinct throughout:

- **A saved specification** — a reusable, named specification kept on the Specifications page, authored once and reused across benchmarks.
- **A benchmark's specification** — the specification actually used to generate a benchmark, snapshotted onto the benchmark row when it is created. The snapshot is read-only and survives later edits to the saved specification it came from (see [Snapshots](#snapshots)).

!!! tip "Free text becomes model instructions"
    Three fields reach MorganaBench **verbatim**: `scenario_description`, each label's `description`, and each acceptance-criteria aspect's `description`. They affect benchmark quality more than anything else, so write them as clear, explicit instructions; see [Writing good specifications](#writing-good-specifications).

## Top-level fields

A specification has the following fields:

| Field | Required | Description |
|-------|----------|-------------|
| `scenario_description` | Yes | Free text describing the overall scenario — the agent, who it serves, and what it is for. Applies to *every* generated case. |
| `number_of_turns_distribution` | Yes | A probability distribution over the number of turns per conversation, e.g. `{1: 0.5, 2: 0.3, 3: 0.2}`. Values must sum to `1.0`. See [Turns](#turns). |
| `categories` | No | The axes of variation, given as a list. Each category is one axis, and its weighted labels set the proportions in which the benchmark varies along it. See [Categories](#categories). |
| `benchmark_acceptance_criteria` | No | *YAML only.* Quality gates every generated turn must pass. See [Acceptance criteria](#acceptance-criteria). |
| `forbidden_label_combinations` | No | *YAML only.* Label combinations that must never co-occur in the same turn. See [Forbidden combinations](#forbidden-combinations). |

Nothing beyond those two is required: a specification with no categories is valid, and its cases then vary as the corpus and MorganaBench vary them rather than in stated proportions. A new specification started in the UI is pre-populated with a default set of categories for the corpus type, each of which can be edited or removed.

### Turns

Tools and [More Like This](more-like-this.md) benchmarks are always single-turn.

For Documents benchmarks, each conversation draws its own length from `number_of_turns_distribution`, independently of the others.
The highest turn count in the distribution is the longest a conversation may get.

The **default specification** weights each additional turn at half the one before it, so short conversations dominate:

| Turns | Share of conversations |
|-------|------------------------|
| 1 | 53.3% |
| 2 | 26.7% |
| 3 | 13.3% |
| 4 | 6.7% |

Extending the distribution therefore adds a few longer conversations rather than lengthening the average one.

Turn counts above your organization's maximum-turns limit are never generated: they are dropped from the distribution and the remaining probabilities re-scaled to sum to `1.0`, so their share is spread over the turn counts that remain.

In the UI, **Max turns** sets the highest turn count and the distribution is rebuilt in the same halving shape, see [Max turns](../ui-guide/benchmarks.md#step-3-generation). Note that the editor has no field for the distribution itself: setting one explicitly is YAML only, and one loaded into the editor is replaced if **Max turns** changes.

## Categories

A category is one axis along which the generated cases should *vary*. Its `labels` name the alternatives along that axis and their probabilities set how often each is drawn, so a category shapes the *mix* of the benchmark rather than sorting cases into fixed buckets. A label is drawn per **turn** by default, so a multi-turn conversation may take a different label on each of its turns; set `scope: conversation` to draw once and hold it for the whole conversation.

`categories` is a list. Each entry is a mapping with the following fields:

| Field | Description |
|-------|-------------|
| `name` | The category identifier (e.g. `response-type`). Must be unique within the specification. |
| `description` | What this category controls. |
| `labels` | The possible values for this axis. See [Labels](#labels). |
| `probabilities` | Optional map of label name → probability, which may instead be set inline per label (`probability:`). Labels left out of the map share the remaining probability evenly; a map covering every label must sum to `1.0`. Omitted entirely ⇒ uniform. |
| `scope` | *YAML only.* When the label is sampled: `turn` (resampled each turn, the default) or `conversation` (sampled once and held constant for the whole conversation). `conversation` scope cannot be combined with `transitions`. |
| `transitions` | *YAML only.* Per-label transition probabilities to the next turn's label, overriding `probabilities` for follow-up turns. Valid only with `turn` scope. Omitted ⇒ each turn is sampled independently. |

## Labels

`labels` is a list. Each entry is a mapping with the following fields:

| Field | Description |
|-------|-------------|
| `name` | The label identifier (e.g. `factoid`). |
| `description` | What this label means for generation. |
| `probability` | How often this label appears within its category, between `0` and `1`. Alternative to the category-level `probabilities` map. |
| `is_unspecified` | Marks the label as the "no constraint" option, leaving its share of cases unconstrained on this axis. Its `name` defaults to `UNSPECIFIED`, which is how the UI presents it. |
| `examples` | *YAML only.* Optional example strings illustrating the label. |
| `transitions` | *YAML only.* Per-label transition probabilities (see [Categories](#categories)). |
| `resource_selection_policy` | *YAML only.* Constraints on which corpus resources are used to generate the turn — e.g. requiring two documents for a comparison question, or a relationship to the resources used in earlier turns. See [Resource selection policy](#resource-selection-policy). |
| `filtering_threshold` | *YAML only.* An extra quality gate that applies only to the turns where this label was selected. It takes the same `threshold` / `acceptance_condition` pair as an [acceptance-criteria](#acceptance-criteria) aspect, and the judge scores the label's own `description`. |

### What a label description controls

A label's `description` shapes the generated turn, and can constrain two different things:

- **Behavior** — how the participants act: the way the user phrases a request and the kind of answer it asks for, covering tone, length, verbosity, formality, expertise, and linguistic correctness. Example: a `verbose` label described as *"a request phrased in more than nine words."*
- **Subject** — what the request is about. Example: a `billing` label described as *"a question about invoices, charges, or refunds."*

A single label may constrain both (*"a verbose question about invoices"*).

A label that names a subject also steers the benchmark toward the parts of the corpus that cover that subject. Naming a subject plainly and positively is what makes this work — see [Writing good specifications](#writing-good-specifications).

### Resource selection policy

`resource_selection_policy` is optional; without it, a turn uses one or two corpus resources and nothing relates them to the resources used in earlier turns. When present, it is a mapping, and each of its keys is optional too:

| Key | Description |
|-----|-------------|
| `min_number_of_resources` | The fewest resources the turn uses, `1` or `2`. Default `1`. |
| `max_number_of_resources` | The most resources the turn uses, `1` or `2` (`2` is the maximum supported). Default `2`. |
| `facets_to_be_equal` | Facet names whose values must match those of one resource from the previous turn. `id` is not a facet name: to require the same resource, use `must_be_same_resource`. |
| `facets_to_be_different` | Facet names whose values must differ from those of every resource used in the previous turn. To require a different resource, use `must_be_different_resource`. |
| `facets_to_be_resumed` | Facet names whose values must match those of a resource from a turn *before* the last one. To require a resource used earlier in the conversation, use `must_be_resumed_resource`. |
| `must_be_same_resource` | Requires the same resources as the previous turn — how a follow-up stays on the same document. Default `false`. |
| `must_be_different_resource` | Requires different resources from the previous turn. Default `false`. |
| `must_be_resumed_resource` | Requires a resource used in a turn *before* the last one, and not the resource of the last turn. Default `false`. |

A specification is rejected when a policy can never be satisfied: `must_be_same_resource` together with `must_be_different_resource`, `must_be_resumed_resource`, `facets_to_be_different` or `facets_to_be_resumed`, since the same resource has the facet values of the previous turn.

A multi-turn category keeps a follow-up on the document its previous turn used:

```yaml
- name: related request
  description: a follow-up question about the same topic as the previous one.
  resource_selection_policy:
    must_be_same_resource: true
```

## Example

A specification for a document-grounded customer-support assistant:

```yaml
scenario_description: |
  The conversation is between a user and a customer-support assistant whose
  answers are grounded in the product knowledge base.

number_of_turns_distribution:
  1: 0.6
  2: 0.3
  3: 0.1

categories:
  - name: question-topic
    description: The part of the product the question is about.
    labels:
      - name: billing
        description: a question about invoices, charges, or refunds.
        probability: 0.4
      - name: shipping
        description: a question about delivery times, tracking, or shipping costs.
        probability: 0.3
      - name: account-settings
        description: a question about account settings, notifications, or privacy preferences.
        probability: 0.3

  - name: coarse-grained-response-type
    description: The type of answer the question expects.
    labels:
      - name: factoid
        description: a question seeking a specific, concise fact such as a name, date, or number.
        probability: 0.5
      - name: yes/no
        description: a question that can be answered with yes or no.
        probability: 0.1
      - name: open-ended
        description: a question inviting a detailed or exploratory response.
        probability: 0.4

  - name: response-verbosity
    description: Whether the question explicitly requests a concise or detailed answer.
    labels:
      - name: concise
        description: explicitly asks for a short, direct answer.
        probability: 0.05
      - name: detailed
        description: explicitly asks for a comprehensive answer with background.
        probability: 0.05
      - name: UNSPECIFIED
        is_unspecified: true
        description: does not explicitly ask for a particular style of answer.
        probability: 0.9

  - name: linguistic-correctness
    description: Degree of linguistic correctness in the user's request.
    labels:
      - name: correct
        description: a request written without linguistic mistakes.
        probability: 0.7
      - name: incorrect
        description: a request with minor typos or grammatical errors.
        probability: 0.3
```

The category distributions above control the variety and realism of the generated cases: 40% of the questions are about billing, roughly half are factoid questions, 90% leave answer length unspecified, and 30% contain minor linguistic errors.

The example is a **document** benchmark. **Tool usage** benchmarks use a specification of the same shape, with their own default categories.

## Writing good specifications

MorganaBench applies a specification one turn at a time:

- **Each turn gets its own selection** — one label from each category, plus material from the corpus.
- **Only the selected label's `description` is used.** The category it belongs to and its other labels are not part of the instruction for that turn.
- **A specification controls how the corpus is used** — including which parts a turn draws on — not what the corpus contains.

The guidelines below follow from those three; the examples continue the customer-support specification above.

1. **Give each label description its full meaning.** Only that one description is used, so write it to make sense on its own. In an `answer-length` category, a middle label described as *"something between brief and thorough"* depends on the other labels, which are not included; *"asks for an answer of three to five sentences"* says the same thing in full. Pointers elsewhere in the specification work the same way: with *"phrased according to the tone rules above"*, the rules themselves are not included, so repeat them in the label. Catch-alls have the opposite problem — a `misc` label described as *"whatever the other labels do not cover"* has no content of its own. Name the cases it stands for (*"a question about account settings or notification preferences"*), or, when that share of conversations should be unconstrained, use the category's `UNSPECIFIED` outcome instead of an ordinary label.

2. **Express intended variation as a category.** Categories set the proportions: what they sample is what the mix reflects. A scenario description saying the assistant *"adapts its explanations to how technical the caller is"* implies a range of callers; a `caller-expertise` category with `non-technical` and `engineer` labels gives each one a stated share. Describe the thing that varies — the caller — not the assistant's answer, which the scenario description already covers.

3. **Name the subjects to cover.** From the same text, a subject label says what the request is about and points the turn at the parts of the corpus that cover it (see [What a label description controls](#what-a-label-description-controls)). Both come from what the label names, so *"a question about delivery times, tracking, or shipping costs"* works, while *"anything other than billing"* names no subject and *"any subject at all"* is what `UNSPECIFIED` already says. A benchmark's coverage comes from the subjects its labels name and the material in the corpus, so a scenario description saying *"users never ask about enterprise licensing"* describes the assistant, not the corpus: licensing questions still appear as long as the knowledge base covers licensing. Restrictions on the assistant read the same way — *"the assistant answers only billing questions"* leaves open what it does with every other question, which is worth stating too.

4. **Keep the parts consistent.** Every description selected for a turn applies at once, so two that pull in opposite directions leave the result to chance. A `terse` label described as *"a single sentence that still covers every edge case"* asks for both; *"a single sentence, even at the cost of edge cases"* settles it. Across fields, a scenario description establishing *"self-service consumer customers"* alongside a `procurement-manager` label states two audiences, and each turn gets one of them. A category description naming *"English, Spanish, and Arabic"* when only `english` and `spanish` labels exist is the mirror case: the mix follows the labels, so the third value never appears. Categories need to fit together too, since one label is selected from each and a benchmark covers every combination — `visit-history` (`first-time-visitor`, `long-time-subscriber`) beside `renewals` (`never-renewed`, `renewed-several-times`) also produces *first-time visitor* with *renewed several times*. When most combinations are unwanted, use a single category whose labels are the pairings that make sense; when only a few are, list them in [`forbidden_label_combinations`](#forbidden-combinations).

5. **Keep the scenario description to what shapes the conversation.** It is the setting for every conversation and is followed closely, so detail from it shows up in the questions. Adding *"the knowledge base is re-indexed nightly and served from a low-latency cache"* invites questions about indexing and caching that the benchmark was not meant to cover.

6. **Describe each turn on its own terms.** Multi-turn conversations stay coherent without help from the descriptions, so a label does not need to refer to the previous turn: *"a follow-up that narrows the question the user asked before"* asks for coherence that is already there, while *"the user asks about one specific detail rather than the whole feature"* describes the turn itself. The fields that shape structure across turns are `scope`, `transitions`, and [`resource_selection_policy`](#resource-selection-policy).

### The specification reviewer

The specification editor in the benchmark creation flow offers a **Review** action, which checks the current scenario description and categories against the guidelines above. Findings come back as remarks anchored to the text each one concerns. Review runs on request rather than automatically, and reviewing again replaces any remarks that are still open. Unlike everything else on this page, the reviewer is a UI feature: it is reached only through that editor, and the CLI has no equivalent.

A remark states the problem and, where a concrete change follows from it, includes that change: a rewrite of the passage, a label to add, a category to add, replace, or merge away, or the conversion of a hand-rolled catch-all label into its category's `UNSPECIFIED` outcome. **Apply** makes the change, **Dismiss** discards the remark. When the fix depends on what the author intended, the remark has no change to apply and asks for a decision instead.

## Acceptance criteria

`benchmark_acceptance_criteria` defines quality gates that each generated turn must pass to be included in the benchmark. It contains a list of `filtering_aspects`, each scored `1`–`5` by an LLM judge against a threshold:

```yaml
benchmark_acceptance_criteria:
  filtering_aspects:
    - name: context free
      description: >
        A subject expert can fully understand the question without reading the
        source document. The question is not vague or ambiguous and does not use
        pronouns without clear referents.
      threshold:
        threshold: 3
        acceptance_condition: ">="
```

| Field | Description |
|-------|-------------|
| `name` | Identifier for the aspect. |
| `description` | The criterion the judge scores against. |
| `threshold.threshold` | The score cutoff, an integer `1`–`5`. |
| `threshold.acceptance_condition` | `">="` (score must meet or exceed the threshold) or `"<="` (must be at or below it). |

## Forbidden combinations

`forbidden_label_combinations` lists label combinations that must never appear together in the same turn. Each entry is a mapping of category name → label name and must name at least two categories; the combination of those labels is what is forbidden:

```yaml
forbidden_label_combinations:
  forbidden_combinations:
    - coarse-grained-response-type: factoid
      response-verbosity: detailed
```

## Statuses

Only saved specifications carry a status; a benchmark's snapshotted specification is part of the benchmark row and has none of its own. Validation is synchronous — YAML that does not validate is rejected rather than stored — so a saved specification is `ready` from the moment it is created and stays `ready` through any number of edits. Deletion is soft: the row remains and is marked `deleted`, which hides it from the Specifications page.

| Status | Meaning |
|--------|---------|
| `ready` | Valid and available for use |
| `deleted` | Deleted, and hidden from the Specifications page |

Two further statuses, `pending` and `failed`, exist as reserved values and are accepted as list filters, but nothing currently produces them.

## Snapshots

Every benchmark **snapshots** its specification onto the benchmark row when it is created — whether that specification was authored from scratch, loaded from a saved one, or loaded and then edited. From then on the benchmark uses its own copy, so later edits to the saved specification never reach benchmarks already generated from it: each benchmark carries the exact specification it was generated against.

The snapshot is viewable read-only from the benchmark detail page at `/benchmark/:id/specification`, and can be saved from there either as a new saved specification or over an existing one. For the steps, see the [Specifications UI Guide](../ui-guide/specifications.md).