Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c59eeb6
[Frontend] Structured decisions API on any generative model
mmastrac Sep 29, 2026
66197f4
[Frontend] Structured decisions: refuse any unknown question field
mmastrac Sep 29, 2026
16fc523
[Frontend] Structured decisions: Jinja decision templates and read st…
mmastrac Sep 29, 2026
374d465
[Frontend] Structured decisions: test that request templates take effect
mmastrac Sep 29, 2026
e82b4c5
[Frontend] Structured decisions: answer macro, and review cleanups
mmastrac Sep 29, 2026
8843350
[Frontend] Structured decisions: trim comments and tests
mmastrac Sep 29, 2026
96cddb0
[Frontend] Structured decisions: models name their read strategy
mmastrac Sep 29, 2026
55366e8
[Frontend] structured decisions: sweep labels per template and tokeni…
mmastrac Sep 29, 2026
142a8f0
[Frontend] structured decisions: seed request field for the label draw
mmastrac Sep 29, 2026
b3b2f20
[Frontend] structured decisions: e2e answers averaged over 16 seeds
mmastrac Sep 29, 2026
ce542c7
[Frontend] structured decisions: comment and docs pass
mmastrac Sep 29, 2026
305fc10
[Frontend] structured decisions: drop request-supplied templates
mmastrac Sep 29, 2026
69ac08b
[Frontend] structured decisions: plain prose in comments, errors and …
mmastrac Sep 29, 2026
31d6459
[Frontend] structured decisions: fix mypy errors
mmastrac Sep 29, 2026
d735dbe
[Frontend] structured decisions: each read sees only its own question
mmastrac Oct 1, 2026
53ea54e
[Frontend] structured decisions: address review (shared read, is_diff…
mmastrac Oct 1, 2026
9a87e76
Merge remote-tracking branch 'upstream/main' into structured-decisions
mmastrac Oct 2, 2026
bdd86e5
[Frontend] structured decisions: opt-in flag, Qwen allowlist, one-opt…
mmastrac Oct 2, 2026
2ea5f52
[Frontend] structured decisions: require a logprobs mode
mmastrac Oct 2, 2026
b90b35b
[Frontend] structured decisions: fixed in-order labels instead of a l…
LucasWilkinson Oct 4, 2026
450f9ea
[Frontend] structured decisions: cap choice at 26 options, labels A-Z
LucasWilkinson Oct 4, 2026
bbf4970
[Frontend] structured decisions: label token ids once, at startup
LucasWilkinson Oct 5, 2026
1281b95
[Frontend] structured decisions: fail at startup when the model canno…
mmastrac Oct 5, 2026
e48e976
Merge branch 'main' into structured-decisions
mmastrac Oct 5, 2026
448d844
Merge branch 'main' into structured-decisions
LucasWilkinson Oct 7, 2026
af0fe17
Fix duplicate chat-template kwargs in decision startup probe
franciscojavierarceo Oct 7, 2026
dccd7a4
Merge branch 'main' into structured-decisions
mmastrac Oct 7, 2026
c85f761
Merge branch 'main' into structured-decisions
mmastrac Oct 7, 2026
8fa7f04
Merge branch 'main' into structured-decisions
LucasWilkinson Oct 7, 2026
fd64fb0
Merge branch 'main' into structured-decisions
LucasWilkinson Oct 8, 2026
c9fb17a
Update vllm/entrypoints/generate/structured_decisions/strategies.py
mmastrac Oct 8, 2026
35c5683
Merge branch 'main' into structured-decisions
mmastrac Oct 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/serving/online_serving/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ For further details on speech to text, please refer to [this page](speech_to_tex
- [Generative Scoring API](generative_scoring.md) (`/generative_scoring`)
- Applicable to [CausalLM models](../../models/generative_models.md) (task `"generate"`).
- Computes next-token probabilities for specified `label_token_ids`.
- [Structured Decisions API](structured_decisions.md) (`/v1/systemone`)
- Applicable to [text generation models](../../models/generative_models.md) with a [chat template](#chat-template).
- Answers typed questions about a state with a probability for every allowed answer.

## Instrumentator APIs

Expand Down
147 changes: 147 additions & 0 deletions docs/serving/online_serving/structured_decisions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Structured Decisions

The `/v1/systemone` endpoint answers a set of typed questions about a state and
returns a probability for every allowed answer.

The endpoint serves generative models (task `"generate"`) that have a chat
template.

## How it works

1. A decision template renders the system prompt: every question and its
allowed answers, each with a single-token label such as `K`. The
user message is the state.
2. Each question is one read: the prompt with the assistant reply prefilled up
to that question's label (`id:` by default), and one generated token.
3. The read returns the logprobs of that question's label tokens. Softmax over
the labels gives the answer's probabilities.

This endpoint does not serve diffusion models yet.

Every read of a request shares the system prompt and the state, so with
`--enable-prefix-caching` the state is prefilled once and each further
question prefills only its answer prefix and reads one token.

## Question types

| type | criteria | answer |
| --- | --- | --- |
| `choice` | map of option name to a description or `null` | `choice`, `probabilities` by option name, `confidence` |

A choice has at least 2 options. A question id is a non-empty string made of any
characters except `:` and newline.

## Example

```bash
curl -s http://localhost:8000/v1/systemone \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3-0.6B",
"state": {"ticket": "My card was charged twice for one order."},
"questions": {
"team": {
"type": "choice",
"instructions": "Which team should handle this ticket?",
"criteria": {
"billing": "payments and refunds",
"shipping": "deliveries",
"security": "account access"
}
}
},
"chat_template_kwargs": {"enable_thinking": false}
}'
```

Response, with probabilities that depend on the model:

```json
{
"id": "decision-...",
"object": "structured_decision",
"created": 1790000000,
"model": "Qwen/Qwen3-0.6B",
"answers": {
"team": {
"type": "choice",
"choice": "billing",
"probabilities": {"billing": 0.97, "shipping": 0.01, "security": 0.02},
"confidence": 0.97
}
},
"usage": {"input_tokens": 142, "output_tokens": 1},
"diagnostics": {
"team": {"label_mass": 0.93, "argmax_is_label": true}
}
}
```

`diagnostics.label_mass` is the probability the model put on the labels across
its whole vocabulary. A low value means most of the probability went to tokens
that are not labels.

## Decision templates

The system prompt comes from a Jinja template, rendered in the same sandboxed
environment as chat templates. The server uses its built-in template unless it
starts with `--decision-template`. That flag takes a file path or the template
inline.

The template receives `instructions` (a string or `None`) and `questions`, a
list of objects with `id`, `type`, `instructions` and `options`. Each option has
`label`, `name` and `description`.

A template may define an `answer(question, label)` macro that returns one
question's answer as the model should write it. The default is `id: label`.
The server renders the answer once per label and compares the tokens to find
where the label goes, then prefills each read up to that point. The system
prompt can call the same macro to show the model the exact reply format.

```jinja
{% macro answer(question, label) %}{{ question.id }} -> {{ label }}{% endmacro %}
Classify the ticket.
{% for q in questions %}
{{ q.instructions }}
{% for o in q.options %}
{{ o.label }} = {{ o.name }}{% if o.description %}: {{ o.description }}{% endif %}

{% endfor %}
{% endfor %}
Reply with one line per question, as: {{ answer({"id": "id"}, "label") }}
```

The answers of all the labels must differ in exactly one token for the model's
tokenizer, with some text before it. If the template breaks that, each request
gets a 400 naming the question.

## Labels

The first time the server uses a template, it tries each label from `A` to
`ZZ` in the template's answer and keeps those that are one token. The label's
token can include a leading space or the colon before it. The server groups
the labels by the rest of that token's text and keeps the largest group, so
every label is tokenized the same way. A question takes single letters first
and two-letter labels only when it has more options than letters. Labels are
shuffled with a seed from a hash of the question, so the first option is not
always `A`, and a repeated question gets the same prompt.

## Limits

| limit | value |
| --- | --- |
| questions per request | 64 |
| options per `choice` | the number of labels the server keeps, at most 128 |

## Request fields

| field | meaning |
| --- | --- |
| `state` | what the questions are about: a string, or JSON that is sent as its JSON text |
| `questions` | question id to `{type, instructions, criteria}`, asked in this order |
| `instructions` | optional context placed ahead of the questions |
| `chat_template_kwargs` | passed to the chat template, for example `{"enable_thinking": false}` |
| `seed` | optional, changes each question's label shuffle. Averaging answers over several seeds reduces label bias. |

A question with any field other than `type`, `instructions` and `criteria` is
rejected with a 400.
1 change: 1 addition & 0 deletions docs/usage/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ When `--api-key` is configured, the following endpoints require Bearer token aut
- `/v1/responses/{response_id}/cancel` - Cancel a response
- `/v1/score` - Scoring API
- `/v1/rerank` - Reranking API
- `/v1/systemone` - Structured decisions API
- `/v1/load_lora_adapter` - Load a LoRA adapter (can alter model behavior; only available when `--enable-lora` is set and `VLLM_ALLOW_RUNTIME_LORA_UPDATING=True`)
- `/v1/unload_lora_adapter` - Unload a LoRA adapter (can alter model behavior; only available when `--enable-lora` is set and `VLLM_ALLOW_RUNTIME_LORA_UPDATING=True`)
- `/inference/v1/generate` - Generate completions (available when `--enable-scale-out` is set, or with `--tokens-only`)
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import string
from typing import Any

import pytest

from vllm.entrypoints.generate.structured_decisions.question_types import (
QUESTION_TYPES,
Option,
Question,
QuestionType,
StructuredDecisionError,
build_question,
register_question_type,
)

LETTERS = tuple(string.ascii_uppercase)


def choice(qid="bucket", criteria=None, instructions="Which team?"):
return build_question(
qid,
"choice",
instructions,
criteria or {"billing": "money", "outage": None, "other": None},
LETTERS,
128,
)


def test_choice_labels_and_options():
q = choice()
assert len(set(q.labels)) == 3 and set(q.labels) <= set(LETTERS)
assert choice().labels == q.labels
assert choice(instructions="Which queue?").labels != q.labels
seeded = build_question(
"bucket",
"choice",
"Which team?",
{"billing": "money", "outage": None, "other": None},
LETTERS,
128,
seed=7,
)
assert seeded.labels != q.labels
wide = build_question(
"q",
"choice",
"",
{str(i): None for i in range(30)},
LETTERS + ("AA", "AB", "AC", "AD"),
128,
)
assert set(wide.labels[:26]) == set(LETTERS)
assert [a.name for a in q.options] == ["billing", "outage", "other"]
assert q.options[0].description == "money"


def test_choice_answer_shape():
q = choice()
answer = q.type.answer(q, [0.2, 0.7, 0.1])
assert answer == {
"type": "choice",
"choice": "outage",
"probabilities": {"billing": 0.2, "outage": 0.7, "other": 0.1},
"confidence": 0.7,
}


@pytest.mark.parametrize(
"qid,type_name,criteria,match",
[
("a:b", "choice", {"x": None, "y": None}, "without ':'"),
("", "choice", {"x": None, "y": None}, "non-empty"),
("q", "nope", {"x": None, "y": None}, "unknown question type"),
("q", "choice", ["x", "y"], "must map option names"),
("q", "choice", {"x": None}, "at least 2"),
("q", "choice", {str(i): None for i in range(27)}, "at most 26"),
],
)
def test_build_question_rejects(qid, type_name, criteria, match):
with pytest.raises(StructuredDecisionError, match=match):
build_question(qid, type_name, "", criteria, LETTERS, 128)


def test_option_limit_is_the_smaller_cap():
with pytest.raises(StructuredDecisionError, match="at most 2 options"):
build_question("q", "choice", "", {"x": None, "y": None, "z": None}, LETTERS, 2)


def test_registered_type_plugs_in():
class BinaryQuestion(QuestionType):
name = "test_binary"

def parse_options(self, qid: str, criteria: Any) -> list[Option]:
return [Option("yes"), Option("no")]

def labels(self, options: list[Option], alphabet: list[str]) -> list[str]:
return ["yes", "no"]

def answer(self, question: Question, probs: list[float]) -> dict[str, Any]:
return {"type": self.name, "yes": probs[0]}

register_question_type(BinaryQuestion)
try:
q = build_question("ok", "test_binary", "Is it fine?", None, LETTERS, 128)
assert q.labels == ("yes", "no")
assert q.type.answer(q, [0.9, 0.1]) == {"type": "test_binary", "yes": 0.9}
with pytest.raises(ValueError, match="already registered"):
register_question_type(BinaryQuestion)
finally:
del QUESTION_TYPES["test_binary"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from types import SimpleNamespace
from typing import Any

from vllm.entrypoints.generate.structured_decisions.strategies import (
NextTokenStrategy,
select_read_strategy,
)


def model_naming(strategy: str) -> Any:
return SimpleNamespace(_model_info=SimpleNamespace(decision_read_strategy=strategy))


def test_strategy_selection():
assert select_read_strategy(model_naming("next_token")) is NextTokenStrategy
assert select_read_strategy(model_naming("not_registered")) is None
Loading
Loading