Skip to content

Commit a41921b

Browse files
christsoCopilot
andauthored
docs(examples): add test vars templating example (#1256)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 91d1d21 commit a41921b

5 files changed

Lines changed: 82 additions & 0 deletions

File tree

examples/features/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Focused examples for specific AgentV capabilities. Find your use case below, the
7373
| [suite-level-input](suite-level-input/) | Prepend a shared system prompt to every test in the suite |
7474
| [suite-level-input-files](suite-level-input-files/) | Share file attachments across every test in the suite |
7575
| [env-interpolation](env-interpolation/) | Inject environment variables into eval config with `${{ VAR }}` |
76+
| [test-vars-templating](test-vars-templating/) | Inject per-test `vars` into `{{name}}` templates in eval fields |
7677

7778
---
7879

@@ -169,6 +170,7 @@ Focused examples for specific AgentV capabilities. Find your use case below, the
169170
| [sdk-programmatic-api](sdk-programmatic-api/) | TypeScript SDK |
170171
| [suite-level-input](suite-level-input/) | Dataset & input |
171172
| [suite-level-input-files](suite-level-input-files/) | Dataset & input |
173+
| [test-vars-templating](test-vars-templating/) | Dataset & input |
172174
| [threshold-grader](threshold-grader/) | LLM grading |
173175
| [tool-evaluation-plugins](tool-evaluation-plugins/) | Tool & agent evaluation |
174176
| [tool-trajectory-advanced](tool-trajectory-advanced/) | Tool & agent evaluation |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Per-Test Vars Templating
2+
3+
Demonstrates `tests[].vars` with `{{name}}` placeholders in eval files.
4+
5+
## Usage
6+
7+
```bash
8+
agentv eval examples/features/test-vars-templating/evals/dataset.eval.yaml
9+
```
10+
11+
## Features
12+
13+
- **Per-test data**: each test defines its own `vars` object
14+
- **Template substitution**: `{{question}}` and dotted paths like `{{expected.answer}}`
15+
- **Suite-level templates**: shared `input` can reference per-test vars too
16+
- **Separate from env interpolation**: `{{question}}` uses test data, `${{ VAR }}` uses environment variables
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Per-test vars templating example
2+
#
3+
# tests[].vars provides per-test data for {{name}} placeholders in eval fields.
4+
# Placeholders support dotted paths like {{expected.answer}}.
5+
#
6+
# Usage:
7+
# agentv eval examples/features/test-vars-templating/evals/dataset.eval.yaml
8+
9+
description: Demonstrates tests[].vars templating in eval fields
10+
11+
execution:
12+
target: llm
13+
14+
input:
15+
- role: system
16+
content: "You are a concise assistant answering {{category}} questions."
17+
18+
tests:
19+
- id: capital-france
20+
vars:
21+
category: geography
22+
question: What is the capital of France?
23+
expected:
24+
answer: Paris
25+
criteria: "Answers {{question}} correctly"
26+
input: "Question: {{question}}"
27+
expected_output: "{{expected.answer}}"
28+
29+
- id: greet-ada
30+
vars:
31+
category: etiquette
32+
person:
33+
name: Ada
34+
expected:
35+
answer: Hello, Ada!
36+
criteria: "Greets {{person.name}} warmly"
37+
input:
38+
- role: user
39+
content: "Say hello to {{person.name}}."
40+
expected_output: "{{expected.answer}}"

packages/core/src/evaluation/validation/eval-validator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const DEPRECATED_TOP_LEVEL_FIELDS = new Map<string, string>([
6969
/** Known fields at the test level. */
7070
const KNOWN_TEST_FIELDS = new Set([
7171
'id',
72+
'vars',
7273
'criteria',
7374
'input',
7475
'input_files',

packages/core/test/evaluation/validation/eval-validator.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,29 @@ describe('validateEvalFile', () => {
145145
expect(result.errors).toHaveLength(0);
146146
});
147147

148+
it('accepts vars without unknown-field warnings', async () => {
149+
const filePath = path.join(tempDir, 'test-vars.yaml');
150+
await writeFile(
151+
filePath,
152+
`tests:
153+
- id: test-1
154+
vars:
155+
question: "What is 2+2?"
156+
expected:
157+
answer: "4"
158+
criteria: "Answers {{question}} correctly"
159+
input: "Question: {{question}}"
160+
expected_output: "{{expected.answer}}"
161+
`,
162+
);
163+
164+
const result = await validateEvalFile(filePath);
165+
166+
expect(result.valid).toBe(true);
167+
const warnings = result.errors.filter((e) => e.severity === 'warning');
168+
expect(warnings).toHaveLength(0);
169+
});
170+
148171
describe('assert field validation', () => {
149172
it('validates assert array items have type field', async () => {
150173
const filePath = path.join(tempDir, 'assert-missing-type.yaml');

0 commit comments

Comments
 (0)