Skip to content

feat(data): per-server task_data schemas, gym env schema, collate validation - #2795

Merged
adil-a merged 3 commits into
mainfrom
data-prep/task-data-schemas
Aug 28, 2026
Merged

adil-a merged 3 commits into
mainfrom
data-prep/task-data-schemas

Conversation

@adil-a

@adil-a adil-a commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A dataset row's task fields have no machine-checkable definition. Each server types what it can on its verify request models. But that contract is invisible to data tooling. A typo'd or mistyped field is discovered at rollout time, or never. At least 12 servers use Pydantic's default extra="ignore" and silently drop unrecognized row fields at the verify boundary. Learning what fields a server needs means reading its source code.

Change

A resources server can now describe its task fields in one small file. This PR ships the machinery and six example servers. The schemas for the other 108 servers follow in one batch (#2800).

1. A server can ship resources_servers/<name>/task_data.py. It exports one symbol, TaskData: a Pydantic model describing the row's task-owned fields. A server whose rows come in several distinct shapes exports one model per shape plus the field that names the shape, and validation picks the right model per row. Example: ruler2 rows carry eval_type; string-match rows must have a list of expected outputs, multichoice rows must have one answer letter. The file is dependency-light: it imports only stdlib, pydantic, and nemo_gym/task_data.py. Data tooling can load it without installing the server's requirements.

2. Schemas describe the future row shape. Today task fields live in two places: most servers keep them as top-level row keys, 14 keep them inside a verifier_metadata dict. We plan to move all task fields under one task_data key later. Schemas are written for that future shape now. Before validating a row, core code normalizes it: framework keys are removed, and verifier_metadata contents are lifted to the top level. If the same key appears in both places with different values, the row is flagged. This way one schema checks today's rows and tomorrow's rows, and no schema needs a rewrite when the move happens. Fields that sit inside verifier_metadata today are marked legacy_location, so the migration knows where each field came from.

3. gym env schema --resources-server <name> prints the schema as JSON Schema.

4. gym dataset collate validates rows against the declaring server's schema. New knob: task_data_validation: off|warn|error, default warn. Warn prints a per-file report (failing rows, ambiguous duplicate keys, undeclared keys). Error fails collation. Servers without a schema are always skipped, so nothing changes for them. Datasets declared by an agent resolve to the resources server the agent references. Self-contained agents (tau2-style) are skipped.

5. CI enforcement, both halves. A test imports every shipped task_data.py and rejects imports outside the allowed set. Pydantic's silent-drop extra="ignore" is banned in schemas (allow is the default, forbid is opt-in).

Field rules encoded in the protocol

Required-ness mirrors the server's wire contract, not what verify() happens to read. Several servers 422 on missing-but-unread fields, and existing datasets must keep validating. JSON-encoded-string fields stay str. Servers with several row shapes key the choice on a field their verify() already reads (ruler2 eval_type, asr_with_pc task_type), never on a new field invented for the schema.

How this was tested

  • 2922 core unit tests pass. 40 are new: normalization and splice, loader, validator, ownership resolution, and the two CI enforcement sweeps.
  • Golden routing gate, base-of-branch vs branch: 0 differences, strict mode, 233 closures. Collation output is byte-identical.
  • Live: gym dataset collate on clean example data prints nothing. A deliberately mistyped row prints the per-row report in warn and fails collation in error. Exact messages verified.
  • gym env schema verified for a schema-bearing server, an empty schema, and a server without one.

Stack

PR 1 of the task-data-schema series. Base: #2717 (data-prep/rs-datasets-collate). Next: #2800 (the 108 per-server schemas), then per-server flips of task_data_validation to error once each server's committed data validates clean.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e4aed2e

@adil-a
adil-a force-pushed the data-prep/task-data-schemas branch from e4aed2e to cefa04e Compare August 26, 2026 16:31
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cefa04e

@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d10ea57

@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3e44b4c

@adil-a
adil-a force-pushed the data-prep/rs-datasets-collate branch from bff41cd to 350ed9c Compare August 26, 2026 17:59
@adil-a
adil-a force-pushed the data-prep/rs-datasets-collate branch from 350ed9c to 4f649fa Compare August 26, 2026 18:42
@adil-a adil-a changed the title feat(data): per-server task_data schemas, gym env schema, collate validation (RFC pillar 2) feat(data): per-server task_data schemas, gym env schema, collate validation Aug 26, 2026
@adil-a
adil-a force-pushed the data-prep/task-data-schemas branch from 3e44b4c to 176039d Compare August 26, 2026 19:25
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 176039d

Comment thread nemo_gym/task_data.py Outdated
names = set(core.model_fields)
names.update(f.alias for f in core.model_fields.values() if f.alias)
return frozenset(names)
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: returning None here disables unknown-field reporting for a root Annotated[Union[...]]. For example, RULER2 can accept lenght instead of its optional length field because the selected model allows extras and the validator never records them. Pydantic returns the selected concrete model after validation, so inspecting its __pydantic_extra__ would make reporting work for unions too. That could also support an explicit schema policy: reject extras, accept and report them, or accept them as intentionally open.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 12a9154, using your approach. The validator now validates and keeps the returned model. Pydantic returns the selected union member, so unknown fields land on its pydantic_extra and get reported for unions too. Your ruler2 example is now a test: a typo'd lenght on a union member is recorded as an unknown key. On the explicit policy: reject maps to extra='forbid', accept-and-report is the default extra='allow' behavior, and 'ignore' stays banned. Intentionally-open payloads are typed as dict fields, so their contents never count as unknown.

ananthsub
ananthsub previously approved these changes Aug 27, 2026
@adil-a

adil-a commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 12a9154

ananthsub
ananthsub previously approved these changes Aug 27, 2026
…idation

A resources server can now ship resources_servers/<name>/task_data.py
exporting a Pydantic TaskData model that types its dataset rows'
task-owned fields. This PR ships the machinery plus the six example
servers; the other 108 schemas follow in one batch.

- nemo_gym/task_data.py: dependency-light leaf module with the schema
  loader, the framework-reserved row keys, and a row validator.
  Schemas are written flat in the planned end-state row shape; rows
  that still carry a legacy verifier_metadata dict have its contents
  spliced up before validation (equal duplicates tolerated,
  conflicting values reported), so one schema validates both today's
  rows and post-row-format-migration task_data contents. Fields
  living in verifier_metadata today are annotated with
  legacy_location so migration tooling has the reverse map.
- gym env schema --resources-server <name>: prints the schema as
  JSON Schema.
- gym dataset collate: validates each row against the declaring
  server's schema behind task_data_validation: off|warn|error
  (default warn; servers without a schema are skipped). Datasets
  declared by agents resolve to the resources server the agent
  references; self-contained agents are skipped.
- Reference schemas for the six example servers, covering the three
  real patterns: top-level fields, verifier_metadata, and stateful
  servers with no task fields.
- CI enforcement: every shipped task_data.py must import only
  stdlib/pydantic/nemo_gym.task_data/other task_data modules, and
  pydantic's silent-drop extra='ignore' is banned.

Verified: full core suite passes; golden routing gate base-vs-branch
is 0-diff strict; live collate smoke on clean data is silent, warn
mode prints the per-row report, error mode fails collation with it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
ref = getattr(inner, "resources_server", None)
rs_name = ref.get("name") if isinstance(ref, (dict, DictConfig)) else getattr(ref, "name", None)
if not isinstance(rs_name, str):
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this works as expected - e.g. in L765 we check:

if other.SERVER_TYPE == "resources_servers" and other.name == rs_name:

I don't think it will work for agent-defined datasets.

But I also consider this non-blocking - can be addressed when we'll be adding schemas for self-contained agents.

Comment thread nemo_gym/task_data.py Outdated
# SPDX-License-Identifier: Apache-2.0
"""Per-server task-data schemas.

A resources server may ship a ``task_data.py`` module next to its ``app.py`` exporting a single

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this description is outdated after you addressed comments from Ananth

@adil-a adil-a Aug 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Updated in ac66f17. The docstring now covers agent-owned schemas: a self-contained agent ships task_data.py under responses_api_agents//, and an agent with a reference uses that resources server's schema.

Comment thread nemo_gym/task_data.py Outdated
agents (which verify in-process) keep their schemas under ``responses_api_agents/<name>/``.
"""
rel = Path(base_folder) / server_name
for root in (Path.cwd(), Path(__file__).resolve().parent.parent):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use component_search_roots here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or even _resolve_under_cwd_or_install - I think it does exactly what you need

@adil-a adil-a Aug 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Done in ac66f17. find_server_dir now resolves through _resolve_under_cwd_or_install with an is_dir validator. This also fixes a real gap: the old code missed NEMO_GYM_EXTRA_ROOTS, so schemas in plugin roots were not found.

Comment thread nemo_gym/task_data.py
self.report.unknown_keys[key] = self.report.unknown_keys.get(key, 0) + 1


def validate_jsonl_rows(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is not used anywhere except tests.

@adil-a adil-a Aug 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True today. Its planned consumer is dataset tooling that validates a whole file against a schema, and the drift test added later in this stack uses it the same way. The docstring wrongly said CLI tooling; fixed in ac66f17 to describe it as the whole-file validation entry point.

Comment thread nemo_gym/train_data_utils.py Outdated
legacy_agent_ref_rows += 1
row[TASK_SOURCE_KEY_NAME] = c.name
if validator is not None:
validator.validate_row(row_index, row)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: I think if we use N repeats we report each broken row N times and the index does not match the index in the jsonl file. I'm not sure how hard it would be to deduplicate and use the original row indices

@adil-a adil-a Aug 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in ac66f17. Collate now validates only the first copy of each repeated line and reports the original jsonl index. Test added: a bad row with num_repeats=3 is reported once, as row 1.

@adil-a

adil-a commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ac66f17

… dedupe, docs, tests

find_server_dir now resolves through _resolve_under_cwd_or_install, so schemas in NEMO_GYM_EXTRA_ROOTS plugin roots are found too. Collate validation now checks only the first copy of a num_repeats-duplicated line and reports the original jsonl index. The module docstring covers agent-owned schemas. The validate_jsonl_rows docstring names its real consumer. Two tests added: an agent with a valid resources_server reference resolves that server's schema end to end, and a bad row under num_repeats=3 is reported once with its file index.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a

adil-a commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b5cf00d

@adil-a

adil-a commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 361d638

@adil-a

adil-a commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b993804

@copy-pr-bot

copy-pr-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

/ok to test b993804

@adil-a, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@adil-a

adil-a commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 361d638

This branch was previously deployed

1 inactive deployment
public — 361d638d Deployed Aug 28, 2026 by copy-pr-bot[bot] via release / finalize / notify #2201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants