Repository navigation
feat(ui_generation): add UI generation environment with an LLM-judge verifier - #5774
Conversation
…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]>
e0b5f23 to
7268330
Compare
|
/ok to test 7268330 |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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.
yaoyu-33
left a comment
There was a problem hiding this comment.
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.pycan leave the reference answer in the policy prompt. - Risk: the environment runs through the
legacy_agentrelay. New environments should usesingle_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.
| if reference is None and messages and messages[-1]["role"] == "assistant": | ||
| reference = messages.pop()["content"] |
There was a problem hiding this comment.
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?
| 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"] |
There was a problem hiding this comment.
Took the suggestion: the combination is refused, with a test.
| ui_generation_environment_server: | ||
| environment_servers: | ||
| legacy_agent: | ||
| entrypoint: app.py | ||
| agent_server: | ||
| type: responses_api_agents | ||
| name: ui_generation_agent |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
|
/ok to test f38cb9d |
|
/ok to test dc9fe88 |
Signed-off-by: yaoyu-33 <[email protected]>
yaoyu-33
left a comment
There was a problem hiding this comment.
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.
|
/ok to test bfb4b0b |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43993201054 |
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_adherenceandqualityfrom 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 / 4by default;reward_scorecan selectprompt_adherence,meanormin. Both scores are reported per rollout, asreward_components, and as means overall and per taskcategory.Verification:
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/completionsto a separate judge model server.finish_reason == "stop") and its JSON matches the schema exactly; it may be fenced as```jsonor follow a leading<think>block. Anything else is a judge failure, never a score: the row is masked (judge_failed, with the cause infailure_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).observe_llm_judge_grading+call_judge+record_parsed_judge_verdict(), called only after a schema-valid verdict.execution_verified: false), so no sandbox is needed.Data:
environments/ui_generation/prepare.pyconverts a task file in a documented generic format into rows. Each line haspromptormessages, plus areference_answer(or a final assistant message), and an optionalidandcategory;--id-fieldand--category-fieldcan read nested fields.resources_servers/ui_generation/data/example.jsonl: 5 tasks; the data check requires exactly 5.example_metrics.jsonandexample_rollouts.jsonl(5 rollouts): both required by the data check that CI runs (+should_validate_data=true).tests/verifier_cases.jsonl: the cases theVERIFIER_FIXTUREbehindgym env test ui_generationruns.task_data.pydeclares 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 ofresources_servers/ui_generationandenvironments/ui_generationis 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.baselineon the changed files (the secrets-detector job): no findings.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, thengym eval run --no-serve ... --concurrency 2 --temperature 1.0 --top-p 1.0 --max-output-tokens 65536. Policy and judge were bothdeepseek-v4.1-flashon an OpenAI-compatible vLLM-backed endpoint.The 8 tasks were the 5 synthetic examples plus 3 made-up tasks in the
messagesformat, converted withprepare.py --id-field ... --category-field meta.stack.healthy.finish_reasonstop) 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_versionstring. After the rename toui-code-judge-v1, the 5 examples were collected again: 5/5 measured, 0 masked, 0 failed, run healthhealthy, all 4/4. Those rollouts are the committedexample_rollouts.jsonl.Weak answers to the synthetic memory-game task, sent to the live
/verify: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
🤖 Generated with Claude Code