feat(graders): add ASTCodeGrader and is_valid_python static code eval… - #669
Open
shobhitagnihotri69 wants to merge 1 commit into
Open
shobhitagnihotri69 wants to merge 1 commit into
shobhitagnihotri69 wants to merge 1 commit into
Conversation
…uator - Implement ASTCodeGrader subclassing Grader for zero-execution static Python AST verification - Support required function/class definition verification - Enforce anti-cheat security policies via disallowed imports and disallowed calls - Add is_valid_python helper for single-line syntax validation - Add comprehensive test coverage in test_graders.py (82/82 passing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
ASTCodeGraderandis_valid_pythonhelper tohud.graders, enabling fast, zero-execution Python AST code evaluation and anti-cheat validation for coding agent rollouts and evaluation benchmarks.Problem / Motivation
Evaluating generated code in agent rollouts currently relies on
BashGrader(running shell commands) or LLM judges.In high-throughput coding agent benchmarks and RL rollouts (e.g. HumanEval, code synthesis, competitive programming):
subprocessoros, or execute dangerous calls likeeval/exec).Solution
ASTCodeGrader(Async Grader):Graderand integrates natively intocombine(...).ast.parsewithout executing code.required_functions,required_classes).disallowed_imports,disallowed_calls).SubScore(info={...})(including extracted functions, classes, imports, and violation lists).is_valid_python(code)(One-liner helper):1.0if valid syntax, else0.0.hud.graders:BashGrader,LLMJudgeGrader).Test Coverage
TestASTCodeGradertohud/tests/test_graders.py:test_is_valid_python_helpertest_ast_grader_valid_codetest_ast_grader_syntax_errortest_ast_grader_required_definitionstest_ast_grader_anti_cheat_disallowed_importstest_ast_grader_anti_cheat_disallowed_callstest_ast_grader_grade_in_combine82 passed in 1.31s).Note
Low Risk
Additive grader module with no execution of agent code; only standard-library AST parsing and new tests, with no changes to existing grading paths.
Overview
Adds static Python code grading to
hud.gradersso benchmarks can check generated code without shelling out or executing untrusted submissions.ASTCodeGraderparses code withast.parseand returns a binarySubScore, optionally enforcing required function/class names and anti-cheat rules (disallowed_imports,disallowed_calls). Diagnostics land inSubScore.info(syntax errors, defined symbols, imports, violations). It follows the existingGrader/combinepattern viaASTCodeGrader.grade(...).is_valid_pythonis a small helper that returns1.0/0.0for syntactic validity only.Both symbols are re-exported from
hud.graders.TestASTCodeGradercovers syntax, required definitions, import/call policies, and composition withcombine.Reviewed by Cursor Bugbot for commit 66b400e. Bugbot is set up for automated code reviews on this repo. Configure here.