Use this file to discover all available pages before exploring further.
Single-turn environments are the simplest type of environment in Verifiers, designed for tasks where the model provides a single response to each prompt. They’re ideal for Q&A tasks, math problems, text transformations, and other one-shot challenges.
Load existing datasets and map to the expected format.
7
Define Reward Functions
8
Reward functions score model responses. They request data by naming arguments:
9
async def correct_answer(completion, answer) -> float: """Check if the answer appears in the response.""" response = completion[-1]["content"] return 1.0 if answer in response else 0.0
10
Available arguments:
11
completion — model’s output (list of messages)
prompt — input messages
answer — from dataset row
info — structured metadata from dataset
state — full rollout state
12
Create Your Environment
13
Combine everything in load_environment():
14
import verifiers as vffrom datasets import load_datasetdef load_environment(): dataset = load_dataset("gsm8k", "main", split="train") async def correct_answer(completion, answer) -> float: response = completion[-1]["content"] return 1.0 if answer in response else 0.0 rubric = vf.Rubric(funcs=[correct_answer]) return vf.SingleTurnEnv( dataset=dataset, system_prompt="You are a helpful math tutor.", rubric=rubric, )
15
Install and Test
16
Install your environment and run a quick evaluation:
17
prime env install my-math-envprime eval run my-math-env -m gpt-4.1-mini -n 5
18
Expected output:
19
Running evaluation on my-math-env with gpt-4.1-miniProgress: 5/5 examples, 15/15 rolloutsReward: 0.87 ± 0.12
For large datasets, defer loading until first access:
from datasets import load_datasetimport verifiers as vfdef get_dataset_builder(split: str = "train", seed: int = 42): """Returns a builder that lazily loads the dataset.""" def build(): ds = load_dataset("my-dataset", split=split) ds = ds.shuffle(seed=seed) return ds return builddef load_environment(): dataset_builder = get_dataset_builder(split="train") eval_builder = get_dataset_builder(split="test") return vf.SingleTurnEnv( dataset=dataset_builder, # built on first access eval_dataset=eval_builder, # built on first access rubric=rubric, )
Benefits:
Avoid loading large datasets during environment initialization
Use symbolic math checking with the built-in MathRubric:
import verifiers as vfdef extract_boxed_answer(completion): import re match = re.search(r'\\boxed\{(.+?)\}', completion[-1]["content"]) return match.group(1) if match else ""parser = vf.Parser(extract_fn=extract_boxed_answer)math_rubric = vf.MathRubric(parser=parser) # Uses math-verify libraryvf_env = vf.SingleTurnEnv( dataset=dataset, system_prompt="Solve the problem and put your answer in \\boxed{}.", parser=parser, rubric=math_rubric,)