Skip to main content
Requirements for Python code generation validation.

Classes

CLASS PythonExecutionReq

Verifies that Python code runs without raising exceptions. Extracts the highest-scoring Python code block from the model’s last output and validates or executes it according to the configured execution mode. Args:
  • timeout: Maximum seconds to allow code to run. Defaults to 5.
  • allow_unsafe_execution: If True, execute code directly with subprocess. Use only with trusted sources.
  • allowed_imports: Allowlist of importable top-level modules. None allows any import.
  • use_sandbox: If True, use llm-sandbox for Docker-based isolated execution.
Attributes:
  • validation_fn: The validation function attached to this requirement; always non-None.