Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

decision: align request validation and option descriptions

Jeffrey Morgan1ba3c76bd4ab
diff --git a/decision/prompts.go b/decision/prompts.go
index 1801b22dc..157ee639a 100644
--- a/decision/prompts.go
+++ b/decision/prompts.go
@@ -24,6 +24,16 @@ func decisionPrompts(context string, fields []compiledField, renderer string) ([
var options []option
for _, c := range f.Choices {
description, ok := c.Description.(string)
+ if c.Description == nil {
+ // Tev1 describes every option: noul as No/Yes, bare choices by key.
+ description, ok = fmt.Sprint(c.Value), true
+ switch c.Value {
+ case false:
+ description = "No"
+ case true:
+ description = "Yes"
+ }
+ }
if !ok || strings.TrimSpace(description) == "" {
return nil, fmt.Errorf("question %q: Tev1 requires nonempty candidate descriptions", f.Name)
}
diff --git a/decision/prompts_test.go b/decision/prompts_test.go
index c452384b3..4fdcc57c1 100644
--- a/decision/prompts_test.go
+++ b/decision/prompts_test.go
@@ -2,6 +2,7 @@ package decision
import (
"encoding/json"
+ "fmt"
"strings"
"testing"
@@ -13,11 +14,12 @@ func TestPublisherPrompts(t *testing.T) {
if err := json.Unmarshal([]byte(`{"model":"decision","state":"Paid €20 & <tag>. Literal \\u2028, quote \" and colon: comma,","questions":{"refund":{"type":"noul","instructions":"Refund requested?"}}}`), &req); err != nil {
t.Fatal(err)
}
- // Publisher contracts: Together's examples/decide.py payload() and Bespoke's
- // parallel_schema.prepare_prompts(), with false/true mapped to No/Yes.
+ // Publisher contracts: Together's examples/decide.py payload(), with
+ // false/true described as No/Yes, and Bespoke's native_schema(), which
+ // describes only the choices the request describes.
for _, tc := range []struct{ renderer, want string }{
{"tev1", `{"state": "Paid €20 & <tag>. Literal \\u2028, quote \" and colon: comma,", "question": "Refund requested?", "options": [{"label": "A", "key": "false", "description": "No"}, {"label": "B", "key": "true", "description": "Yes"}]}`},
- {"", `{"context": "Paid €20 & \u003ctag\u003e. Literal \\u2028, quote \" and colon: comma,", "schema": [{"name": "refund", "description": "Refund requested?", "choices": [{"code": "A", "value": false, "description": "No"}, {"code": "B", "value": true, "description": "Yes"}]}]}` + "\n\nRequested field: \"refund\""},
+ {"", `{"context": "Paid €20 & \u003ctag\u003e. Literal \\u2028, quote \" and colon: comma,", "schema": [{"name": "refund", "description": "Refund requested?", "choices": [{"code": "A", "value": false}, {"code": "B", "value": true}]}]}` + "\n\nRequested field: \"refund\""},
} {
t.Run(tc.renderer, func(t *testing.T) {
compiled, err := Compile(req, tc.renderer)
@@ -48,6 +50,7 @@ func TestTevQuestions(t *testing.T) {
if err := compiled.Render(func(messages []api.Message) (string, error) { return messages[0].Content, nil }); err != nil {
t.Fatal(err)
}
+ descriptions := [][]string{{"Charges and refunds", "technical"}, {"No", "Yes"}, {"Routine", "Urgent", "Emergency"}}
for i, row := range compiled.Request.Rows {
var payload struct {
State string
@@ -62,15 +65,19 @@ func TestTevQuestions(t *testing.T) {
t.Fatalf("question %d was not compiled independently: %s", i, row.Prompt)
}
for j, option := range payload.Options {
- if option.Label != row.Candidates[j] || option.Description != f.Choices[j].Description || option.Key == "" {
+ if option.Label != row.Candidates[j] || option.Description != descriptions[i][j] || option.Key == "" {
t.Fatalf("question %d option %d: %+v", i, j, option)
}
}
}
for _, count := range []int{24, 25, 26} {
- q, _ := req.Questions.Get("urgency")
- q.Criteria = json.RawMessage(`["x"` + strings.Repeat(`,"x"`, count-1) + `]`)
- req.Questions.Set("urgency", q)
+ q, _ := req.Questions.Get("department")
+ criteria := make([]string, count)
+ for i := range criteria {
+ criteria[i] = fmt.Sprintf(`"%d":"x"`, i)
+ }
+ q.Criteria = json.RawMessage(`{` + strings.Join(criteria, ",") + `}`)
+ req.Questions.Set("department", q)
_, err := Compile(req, "tev1")
if (err == nil) != (count == 24) {
t.Errorf("Tev1 accepted %d candidates: %v", count, err)
diff --git a/decision/systemone.go b/decision/systemone.go
index e401c3b2b..3922d11ed 100644
--- a/decision/systemone.go
+++ b/decision/systemone.go
@@ -29,6 +29,29 @@ type Compiled struct {
messages [][]api.Message
}
+// ValidateLimits checks request limits shared by all decision backends.
+func ValidateLimits(req Request) error {
+ if n := req.Questions.Len(); n < 1 || n > 64 {
+ return fmt.Errorf("questions must contain 1–64 fields")
+ }
+ if len(req.Videos) > 0 {
+ return fmt.Errorf("video inputs are not supported")
+ }
+ if state, err := content(req.State); err == nil && strings.TrimSpace(state) == "" && len(req.Images) == 0 {
+ return fmt.Errorf("state must not be empty")
+ }
+ for name, q := range req.Questions.All() {
+ if q.Type != "score" {
+ continue
+ }
+ var levels []json.RawMessage
+ if err := json.Unmarshal(q.Criteria, &levels); err != nil || len(levels) < 2 || len(levels) > 10 {
+ return fmt.Errorf("question %q: score criteria must be an array of 2–10 levels", name)
+ }
+ }
+ return nil
+}
+
func Compile(req Request, encoding string) (*Compiled, error) {
switch encoding {
case "", "tev1", "clef", "strands":
@@ -38,11 +61,8 @@ func Compile(req Request, encoding string) (*Compiled, error) {
if strings.TrimSpace(req.Model) == "" {
return nil, fmt.Errorf("model is required")
}
- if req.Questions.Len() < 1 || req.Questions.Len() > 64 {
- return nil, fmt.Errorf("questions must contain 1–64 fields")
- }
- if len(req.Videos) > 0 {
- return nil, fmt.Errorf("video inputs are not supported")
+ if err := ValidateLimits(req); err != nil {
+ return nil, err
}
if len(req.Images) != 0 && encoding != "clef" {
return nil, fmt.Errorf("image inputs are not supported by this decision model")
@@ -144,7 +164,9 @@ func compileField(name string, q Question) (compiledField, error) {
return f, fmt.Errorf("instructions must be a nonempty string, object, or array")
}
f.Description = description
- add := func(value any, description string) {
+ // Choices carry only the descriptions the request gives, as in Bespoke's
+ // native_schema() for Nimble.
+ add := func(value any, description any) {
f.Choices = append(f.Choices, Choice{string(rune('A' + len(f.Choices))), value, description})
}
switch q.Type {
@@ -155,7 +177,7 @@ func compileField(name string, q Question) (compiledField, error) {
return f, fmt.Errorf("noul criteria must be an object of true/false descriptions")
}
}
- no, yes := "No", "Yes"
+ var no, yes any
for key, value := range criteria.All() {
if value == nil {
return f, fmt.Errorf("noul descriptions must be strings")
@@ -188,7 +210,7 @@ func compileField(name string, q Question) (compiledField, error) {
if strings.TrimSpace(key) == "" {
return f, fmt.Errorf("choice keys must not be empty")
}
- description := key
+ var description any
if value != nil {
description = *value
}
diff --git a/decision/systemone_test.go b/decision/systemone_test.go
index 4a15f87ac..751e6df73 100644
--- a/decision/systemone_test.go
+++ b/decision/systemone_test.go
@@ -74,7 +74,7 @@ func TestCompile(t *testing.T) {
t.Fatalf("schema order changed: %+v", payload.Schema)
}
}
- if got := payload.Schema[0].Choices; got[0].Value != "billing" || got[1].Value != "technical" || got[1].Description != "technical" {
+ if got := payload.Schema[0].Choices; got[0].Value != "billing" || got[1].Value != "technical" || got[1].Description != nil {
t.Fatalf("choice order or null description changed: %+v", got)
}
if payload.Schema[1].Description != `{"rule":"Explicit refund request?","notes":["Only facts"]}` {
@@ -216,11 +216,15 @@ func TestInvalidRequests(t *testing.T) {
}
req := testRequest(t)
q, _ := req.Questions.Get("urgency")
- q.Criteria = json.RawMessage(`["x"` + strings.Repeat(`,"x"`, 26) + `]`)
- req.Questions.Set("urgency", q)
- for _, encoding := range []string{"", "clef"} {
- if _, err := Compile(req, encoding); err == nil {
- t.Fatalf("encoding %q accepted 27 candidates", encoding)
+ for _, levels := range []int{1, 2, 10, 11, 27} {
+ q.Criteria = json.RawMessage(`["x"` + strings.Repeat(`,"x"`, levels-1) + `]`)
+ req.Questions.Set("urgency", q)
+ for _, encoding := range []string{"", "tev1", "clef", "strands"} {
+ _, err := Compile(req, encoding)
+ valid := levels >= 2 && levels <= 10
+ if (err == nil) != valid {
+ t.Fatalf("encoding %q, %d score levels: error = %v, want valid = %v", encoding, levels, err, valid)
+ }
}
}
}
diff --git a/decision/types.go b/decision/types.go
index 1cebf8699..758bddb5e 100644
--- a/decision/types.go
+++ b/decision/types.go
@@ -30,7 +30,7 @@ type Question struct {
type Choice struct {
Code string `json:"code"`
Value any `json:"value"`
- Description any `json:"description"`
+ Description any `json:"description,omitempty"`
}
// Field is a question's schema as presented to the model.
diff --git a/docs/capabilities/decision.mdx b/docs/capabilities/decision.mdx
index 264092e9f..8e23702f7 100644
--- a/docs/capabilities/decision.mdx
+++ b/docs/capabilities/decision.mdx
@@ -118,7 +118,7 @@ Example response:
| --- | --- | --- |
| `choice` | 2–26 named options with descriptions | The most likely option and each option's probability |
| `noul` | Descriptions for `"false"` and `"true"` | The probability of `true`, from 0 to 1 |
-| `score` | 2–26 descriptions, ordered from lowest to highest | The probability-weighted average of the zero-based levels |
+| `score` | 2–10 descriptions, ordered from lowest to highest | The probability-weighted average of the zero-based levels |
For the urgency criteria below:
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index 675c8bb59..b6bf8b777 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -872,10 +872,8 @@ components:
properties:
"false":
type: string
- default: "No"
"true":
type: string
- default: "Yes"
additionalProperties: false
SystemOneScoreQuestion:
title: Score
@@ -889,9 +887,9 @@ components:
$ref: "#/components/schemas/SystemOneContent"
criteria:
type: array
- description: Descriptions ordered from the lowest score (index 0) to the highest. Defines a scale from 0 to the number of criteria minus 1. The maximum number of levels depends on the model.
+ description: Descriptions ordered from the lowest score (index 0) to the highest. Defines a scale from 0 to the number of criteria minus 1.
minItems: 2
- maxItems: 26
+ maxItems: 10
items:
type: string
SystemOneRequest:
@@ -978,7 +976,7 @@ components:
score:
type: number
minimum: 0
- maximum: 25
+ maximum: 9
description: Probability-weighted average of the zero-based criterion indices, from 0 to the number of criteria minus 1. Not rounded to a level or normalized to 0–1.
legend:
type: object