Skip to content

feat(ui_generation): add UI generation environment with an LLM-judge verifier - #5774

Merged
yaoyu-33 merged 4 commits into
NVIDIA-NeMo:mainfrom
titu1994:ui-generation-env
Nov 17, 2026
Merged

yaoyu-33 merged 4 commits into
NVIDIA-NeMo:mainfrom
titu1994:ui-generation-env

Conversation

@titu1994

@titu1994 titu1994 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds ui_generation, a single-turn environment for front-end UI generation graded by an LLM judge.

The policy gets a request for a web UI (for example a Next.js page, a React component or a plain HTML page, each in one file) and answers in Markdown. An LLM judge reads only the code in the answer's fenced blocks. It returns one JSON verdict that scores prompt_adherence and quality from 0 to 4, using the task's reference answer as a guideline; the reference answer is never shown to the policy.

The reward is quality / 4 by default; reward_score can select prompt_adherence, mean or min. Both scores are reported per rollout, as reward_components, and as means overall and per task category.

Verification:

  • The rubric (resources_servers/ui_generation/prompts/judge.yaml) is the judge's system message. The case is one JSON user message with the keys the rubric names (prompt, original_guideline, candidate_answer), sent over /v1/chat/completions to a separate judge model server.
  • A verdict counts only when the judge finished (finish_reason == "stop") and its JSON matches the schema exactly; it may be fenced as ```json or follow a leading <think> block. Anything else is a judge failure, never a score: the row is masked (judge_failed, with the cause in failure_reason) and keeps its answer for re-judging. Judge calls that get a 408, 429 or 5xx reply, time out or lose the connection are retried (judge_max_attempts).
  • A cut-off or empty policy answer scores 0 without a judge call.
  • Grading path A: observe_llm_judge_grading + call_judge + record_parsed_judge_verdict(), called only after a schema-valid verdict.
  • Nothing is executed or rendered (the rubric requires execution_verified: false), so no sandbox is needed.

Data:

  • environments/ui_generation/prepare.py converts a task file in a documented generic format into rows. Each line has prompt or messages, plus a reference_answer (or a final assistant message), and an optional id and category; --id-field and --category-field can read nested fields.
  • The only committed data are the files Gym's checks require, all synthetic and written for this PR:
    • resources_servers/ui_generation/data/example.jsonl: 5 tasks; the data check requires exactly 5.
    • example_metrics.json and example_rollouts.jsonl (5 rollouts): both required by the data check that CI runs (+should_validate_data=true).
    • tests/verifier_cases.jsonl: the cases the VERIFIER_FIXTURE behind gym env test ui_generation runs.
  • task_data.py declares the row schema.

Scaffolded with gym env init --environment ui_generation --profile custom-gym-verifier (manifest-backed, experimental: true, verified: false). No issue: new environment.

Validation

  • gym env test +entrypoint=resources_servers/ui_generation +should_validate_data=true (the CI command): 61 passed, data validated; coverage of resources_servers/ui_generation and environments/ui_generation is 97.9%.
  • gym env validate ui_generation: manifest, components and dataset pass (example, 5 rows).
  • gym env test ui_generation: verifier fixture, 5 cases pass (full reward, zero reward with and without a judge call, two malformed requests).
  • pytest tests/unit_tests/data/test_task_data.py: 435 passed (schema present, committed rows validate).
  • pre-commit run --all-files: passes, no other files touched.
  • detect-secrets-hook --baseline .github/workflows/config/.secrets.baseline on the changed files (the secrets-detector job): no findings.
  • Not run: gym env publish ui_generation (a local readiness check; the validation and fixture it reruns pass).

Rollouts

Local smoke run: gym env start --environment ui_generation --model-type vllm_model, then gym eval run --no-serve ... --concurrency 2 --temperature 1.0 --top-p 1.0 --max-output-tokens 65536. Policy and judge were both deepseek-v4.1-flash on an OpenAI-compatible vLLM-backed endpoint.

The 8 tasks were the 5 synthetic examples plus 3 made-up tasks in the messages format, converted with prepare.py --id-field ... --category-field meta.stack.

  • 8/8 measured, 0 masked, 0 failed, run health healthy.
  • Mean reward 0.97: seven 4/4 and one 3/3. On the 3/3 the judge flagged a real bug, a pending mismatch timeout that survives a reshuffle.
  • Per-category means: html 0.875, nextjs 1.0, react 1.0.
  • Raw judge replies (bare JSON verdicts, finish_reason stop) were inspected from the vLLM transport log.

That run and the weak-answer checks below used the same code apart from the verdict's schema_version string. After the rename to ui-code-judge-v1, the 5 examples were collected again: 5/5 measured, 0 masked, 0 failed, run health healthy, all 4/4. Those rollouts are the committed example_rollouts.jsonl.

Weak answers to the synthetic memory-game task, sent to the live /verify:

Answer Adherence/quality Reward
Working but incomplete (judge: no move counter, win message or reshuffle; matched cards can be reset) 1/1 0.25
React snippet for an HTML task 0/1 0.25
Stub with a TODO 0/0 0.0
Prose only 0/0 0.0

Use a judge from a different family than the policy for real measurements, as the README says.

Compatibility and benchmark impact

None. New environment only; no shared code changes.

Checklist

  • I have read the contributing guidelines.
  • The change is focused.
  • Tests added and pass locally.
  • Documentation added (environment and resources-server READMEs).
  • Pre-commit checks pass locally.
  • New source files include the Apache-2.0 SPDX header.
  • All commits have DCO sign-off.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 6, 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.

…verifier

Single-turn front-end UI generation (for example a Next.js page, a React
component or a plain HTML page in one file). An LLM judge reads only the
fenced code of the policy's answer and scores prompt adherence and quality
from 0 to 4 against the task's reference answer as a guideline; the reward
is quality / 4 by default (reward_score selects prompt_adherence, mean or
min). The verdict must come from a finished judge reply and match the
rubric's JSON schema exactly; any other reply masks the row as
judge_failed instead of scoring it. Cut-off or empty policy answers score 0
without a judge call.

prepare.py converts a task file in a documented generic format (prompt or
messages plus a reference answer, optional id and category) into rows. The
committed examples are 5 synthetic tasks written for Gym.

Signed-off-by: Somshubra Majumdar <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@titu1994
titu1994 marked this pull request as ready for review November 6, 2026 23:16
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers benchmark-onboarding Self-contained benchmark onboarding community-request Issue reported or requested by someone from the community needs-review PR is ready for code review and waiting on a reviewer labels Nov 7, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 9, 2026
@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test 7268330

@cmunley1

Copy link
Copy Markdown
Contributor

/review

@nemo-automation-bot nemo-automation-bot Bot removed the community-request Issue reported or requested by someone from the community label Nov 12, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 12, 2026 03:02
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

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.

HOLD

I found one BLOCKER, two RISKs, and one NOTE. The blocker rewrites submitted code before grading; the other correctness issues omit task context from the judge and duplicate a saved rollout's task key.

I inspected all 22 changed files across the three review topics and traced the affected model, verification, data-validation, and aggregation paths. The shared judge retry and masking paths look consistent with their contracts. The PR supplies representative smoke evidence, but I didn't execute tests or reproduce those runs in this read-only review.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

Comment thread resources_servers/ui_generation/app.py Resolved
Comment thread resources_servers/ui_generation/app.py Resolved
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 12, 2026

@yaoyu-33 yaoyu-33 left a comment

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.

Thanks for this environment, and for the thorough PR description and smoke evidence. The masking split is right where it matters most: every judge failure (transport errors, non-retryable 4xx, finish_reason != "stop", invalid JSON or schema) reaches judge_failsafe and is masked, while a truncated or empty policy answer scores 0 without a judge call. Masked rows are also excluded before compute_metrics, so the per-category means only count scored rows.

The inline comments hold three risks and four smaller notes:

  • Risk: prepare.py can leave the reference answer in the policy prompt.
  • Risk: the environment runs through the legacy_agent relay. New environments should use single_agent_turn_legacy, and the committed rollouts would then need to be collected again.
  • Risk: a long but complete answer can overflow the judge's context. That row is then masked instead of scored.

We also agree with the existing review threads on app.py:195 (think-tag stripping inside code), app.py:187 (system context the judge never sees) and example_rollouts.jsonl:3 (the task index), and with @cmunley1's comment on the SHA-256 pin in judge.yaml:4. Replies with extra evidence are on those threads.

One question: is there a dataset or training run lined up for this environment? The generic prepare.py format and the four reward_score modes would be easier to review against a real consumer.

Not verified by us: real-model runs. The 61 PR tests pass locally, and a scratch mutation run showed they catch 18 of 19 injected faults.

Comment thread environments/ui_generation/prepare.py Outdated
Comment on lines +61 to +62
if reference is None and messages and messages[-1]["role"] == "assistant":
reference = messages.pop()["content"]

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.

environments/ui_generation/prepare.py:61-62

When a messages task ends with an assistant message and also has reference_answer, the assistant turn is not popped. It stays in responses_create_params.input, so the policy sees the answer (usually the reference itself) and its prompt ends on an assistant turn. That breaks the "never shown to the policy" guarantee in the README and the docstring. Could this refuse the combination (or always pop the trailing assistant turn), with a test for the both-given case?

Suggested change
if reference is None and messages and messages[-1]["role"] == "assistant":
reference = messages.pop()["content"]
if messages and messages[-1]["role"] == "assistant":
if reference is not None:
raise TaskFormatError(f"line {line_number}: final assistant message conflicts with 'reference_answer'")
reference = messages.pop()["content"]

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.

Took the suggestion: the combination is refused, with a test.

Comment on lines +22 to +28
ui_generation_environment_server:
environment_servers:
legacy_agent:
entrypoint: app.py
agent_server:
type: responses_api_agents
name: ui_generation_agent

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.

environments/ui_generation/config.yaml:22-28

New environments should run on agent sessions instead of the legacy_agent relay; gym env init still scaffolds the relay. simple_agent already supports sessions and this server is stateless, so single_agent_turn_legacy should work as is, as it does for instruction_following. After switching, collecting example_rollouts.jsonl again in one run would also fix the duplicated task index on its line 3.

Suggested change
ui_generation_environment_server:
environment_servers:
legacy_agent:
entrypoint: app.py
agent_server:
type: responses_api_agents
name: ui_generation_agent
ui_generation_environment_server:
environment_servers:
single_agent_turn_legacy:
entrypoint: app.py
resources_server:
type: resources_servers
name: ui_generation_resources_server
agent_server:
type: responses_api_agents
name: ui_generation_agent

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.

Switched to single_agent_turn_legacy as suggested; validated and used for the new rollouts.

messages: []
temperature: 1.0
top_p: 1.0
max_tokens: 65536

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.

resources_servers/ui_generation/configs/ui_generation.yaml:17

A complete but long answer can overflow the judge's context. The policy may write up to 65,536 tokens, and the judge's input also holds the rubric, the prompt and the reference, while max_tokens: 65536 is reserved for its output. The judge then returns a 400 or finish_length, which is masked (not retried, see app.py:151), so the longest answers drop out of the score and the training signal instead of being graded. Could the README or config state the minimum judge context for these defaults, and could the smoke report the masked-row rate? A cheap related improvement: accept a ```JSON fence and prose before the fence in _FENCE_RE, so formatting noise from the judge masks fewer rows.

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.

Documented the context the defaults need (about 160k tokens) and that a shorter one masks the longest answers. The cross-family smoke masked 0/5 rollouts and 1/5 probes; that one was a schema omission, not an overflow. _FENCE_RE now accepts any-case fences and prose around them.

Comment thread environments/ui_generation/prepare.py Outdated
if not isinstance(value, str) or not value:
raise TaskFormatError(f"line {line_number}: '{path}' must be a nonempty string")
metadata[key] = value
return {"responses_create_params": {"input": messages}, "verifier_metadata": metadata}

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.

environments/ui_generation/prepare.py:72-79

Suggestion: the id only lands in verifier_metadata.id, but task materialization reads identity from a top-level task_id / problem_id / instance_id (task_materialization.py:20). Every row therefore gets a positional task ID, which shifts when rows or datasets are added or reordered. Writing the id as a top-level task_id here and in data/example.jsonl would keep IDs stable for resume and for comparing runs.

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.

Done: the id is now a top-level task_id in prepare.py output and in data/example.jsonl, and task_data.py declares it.


# The judge. Supply judge_base_url, judge_api_key and judge_model_name from env.yaml, like the policy_* keys
# (oc.select keeps static validation, which loads no env.yaml, working offline). Use a judge from a different
# model family than the policy where possible: a judge shares the preferences of its own family.

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.

resources_servers/ui_generation/configs/ui_generation.yaml:23-25

The only real-model evidence so far uses the same model as policy and judge, which this comment warns against. Not blocking for an experimental environment, but could you add one smoke with a judge from a different family, covering the 5 examples, the weak-answer table and one gamed answer (a stub with a comment addressed to the grader inside the code)? Please report the mean reward, the per-category means and the masked count.

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.

Cross-family smoke (policy DeepSeek v4.1 flash, judge Qwen 3.8 flash): 5 examples mean reward 0.95 (html 1.0, nextjs 0.875, react 1.0; 0 masked); weak answers 0.25 / 0 / 0; gamed stub with a note to the grader 0/0; 1 probe masked for a missing verdict key.

assert row["failure_kind"] == "judge_failed"


def test_a_rate_limited_judge_call_is_retried(monkeypatch) -> 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.

resources_servers/ui_generation/tests/test_app.py:347-357

Nit: this test raises ConnectionError("reset"), so it covers a lost connection, not a 429. Could it be renamed, or changed to return a 429 reply (an aiohttp.ClientResponseError with status=429) so the name matches what it checks?

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.

Now raises a real 429 ClientResponseError.

# A model server with a reasoning parser returns the judge's reasoning as a leading <think> block.
think = _LEADING_THINK_RE.match(content)
if think:
reasoning = reasoning or think.group(1).strip()

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.

resources_servers/ui_generation/app.py:154-158

Nit: no test checks that reasoning_content takes precedence over an inline think block. Swapping the order to think.group(1).strip() or reasoning still passes the whole suite. One test with both present would pin which one is recorded as judge_reasoning.

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.

Added a test pinning that reasoning_content wins.

…env server

- Strip only complete leading <think> blocks from the policy answer, so
  think-tag text inside submitted code reaches the judge unchanged.
- Give the judge the task as the policy saw it: the user prompt as text,
  or the whole role-labelled conversation (request instructions first as
  a system message, then system, user and earlier assistant turns) when
  there is more context. The rubric describes that representation; the
  reference answer stays separate.
- Accept a JSON verdict in a fence of any case and with prose around it.
- prepare.py refuses a task with both a final assistant message and
  reference_answer, so an answer never stays in the policy's prompt, and
  writes the id as the row's top-level task_id (stable task identity).
- task_data.py declares task_id at the top level; a test fails when its
  verifier fields drift from UiGenerationVerifierMetadata.
- Run the environment on single_agent_turn_legacy instead of the
  legacy_agent relay; the 5 example rollouts are re-collected in one run
  (task keys (0,0)..(4,0)) with a judge from a different model family.
- Document the judge context the defaults need (about 160k tokens) and
  that a shorter one masks the longest answers.
- Tests: reasoning_content wins over an inline think block, a real 429
  is retried, think literals in code, consecutive leading think blocks,
  conversation/instructions transcripts; drop the stale SHA-256 pin note
  in the rubric header.

Signed-off-by: Somshubra Majumdar <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test f38cb9d

cmunley1
cmunley1 previously approved these changes Nov 16, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test dc9fe88

@yaoyu-33 yaoyu-33 left a comment

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.

Refreshed the stale ui_generation lock to match Gym's existing openai==2.45.0 requirement. Only the lockfile changes. Independent delta review found no blocker. On ws with uv 0.13.4: targeted lock check and all 317 managed-project lock/policy checks pass; applicable pre-commit hooks pass. Model rollouts were not rerun for this lock-only repair; existing rollout evidence is author-reported. Final GitHub CI remains outstanding.

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Nov 17, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test bfb4b0b

@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43993201054

Merged via the queue into NVIDIA-NeMo:main with commit 5d6429f Nov 17, 2026
71 checks passed
@titu1994
titu1994 deleted the ui-generation-env branch November 17, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers benchmark-onboarding Self-contained benchmark onboarding feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants