> ## Documentation Index
> Fetch the complete documentation index at: https://ibm-llm-runtime-aaf3a78b.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# mellea.stdlib.requirements.python_reqs

> Requirements for Python code generation validation.

export const SidebarFix = () => <script dangerouslySetInnerHTML={{
  __html: `
        (function () {
          const INTERVAL_MS = 500;

          const upgradeSidebar = () => {
            const links = document.querySelectorAll('a[href^="#"]');

            links.forEach((link) => {
              if (link.dataset.badged === "true") return;

              const rawText = (link.textContent || "").trim();

              // ========== FUNC ==========
              if (rawText.startsWith("FUNC ")) {
                const label = rawText.replace(/^FUNC\\s+/, "").trim();

                while (link.firstChild) link.removeChild(link.firstChild);

                // 👉 Make the whole link a single flex row & prevent wrapping
                link.style.display = "flex";
                link.style.alignItems = "center";
                link.style.whiteSpace = "nowrap";
                link.style.columnGap = "0.5rem";

                const badge = document.createElement("span");
                badge.style.marginRight = "0.5rem";
                badge.style.display = "inline-flex";
                badge.style.alignItems = "center";
                badge.style.borderRadius = "9999px";
                badge.style.padding = "0rem 0.6rem";
                badge.style.fontSize = "0.5rem";
                badge.style.fontWeight = "700";
                badge.style.letterSpacing = "0.05em";
                badge.style.backgroundColor = "rgba(48, 100, 227, 0.20)";
                badge.style.color = "#1D4ED8";

                badge.textContent = "FUNC";

                link.appendChild(badge);
                link.appendChild(document.createTextNode(label));
                link.dataset.badged = "true";
                return;
              }

              // ========== CLASS ==========
              if (rawText.startsWith("CLASS ")) {
                const label = rawText.replace(/^CLASS\\s+/, "").trim();

                while (link.firstChild) link.removeChild(link.firstChild);

                // 👉 Same flex / nowrap treatment for class links
                link.style.display = "flex";
                link.style.alignItems = "center";
                link.style.whiteSpace = "nowrap";
                link.style.columnGap = "0.5rem";

                const badge = document.createElement("span");
                badge.style.marginRight = "0.5rem";
                badge.style.display = "inline-flex";
                badge.style.alignItems = "center";
                badge.style.borderRadius = "9999px";
                badge.style.padding = "0rem 0.6rem";
                badge.style.fontSize = "0.5rem";
                badge.style.fontWeight = "700";
                badge.style.letterSpacing = "0.05em";
                badge.style.backgroundColor = "rgba(74, 222, 128, 0.20)";
                badge.style.color = "#15803D";

                badge.textContent = "CLASS";

                link.appendChild(badge);
                link.appendChild(document.createTextNode(label));
                link.dataset.badged = "true";
                return;
              }
            });
          };

          upgradeSidebar();
          setInterval(upgradeSidebar, INTERVAL_MS);
        })();
      `
}} />;

<SidebarFix />

Requirements for Python code generation validation.

## Classes

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />

### <span className="ml-2 inline-flex items-center rounded-full px-2 py-1 text-[0.7rem] font-bold tracking-wide bg-[#4ADE8033]/20 text-[#15803D]">CLASS</span> `PythonExecutionReq` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.7.0.dev0/mellea/stdlib/requirements/python_reqs.py#L162" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Verifies that Python code runs without raising exceptions.

Optionally validates that captured stdout does not exceed a size limit,
eliminating the double-execution cost of separate OutputSizeLimit checks.

Extracts the highest-scoring Python code block from the model's last output
and validates or executes it according to the configured execution tier.

Use `execution_tier` to select behavior by intent:

* `"static"` (default) — parse and import-check only, no execution.
* `"local_unsafe"` — subprocess execution, no policy restrictions.
* `"local"` — subprocess execution with a declared capability policy.
* `"docker_unsafe"` — Docker-isolated execution, no policy restrictions.
* `"docker"` — Docker-isolated execution with a declared capability policy.

**Args:**

* `execution_tier`: One of `"static"`, `"local_unsafe"`, `"local"`,
  `"docker_unsafe"`, or `"docker"`.  Defaults to `"static"`.
* `policy`: Override the tier's default policy.
  Ignored for `"static"` and unsafe tiers unless explicitly provided.
* `allowed_imports`: Allowlist of importable top-level
  modules.  `None` allows any import.
* `max_output_chars`: Maximum allowed stdout size in characters.
  None = no size check (default). When set, adds output size validation
  in the same execution pass, avoiding the double-execution cost of using
  OutputSizeLimit. Only enforced for tiers that execute code (local\_unsafe,
  local, docker\_unsafe, docker); static tier skips output check.
* `timeout`: Deprecated.  Pass `policy=CapabilityPolicy(timeout=N)`
  instead.  When provided, overrides the policy timeout.
* `allow_unsafe_execution`: Deprecated.  Use
  `execution_tier="local_unsafe"` instead.
* `use_sandbox`: Deprecated.  Use `execution_tier="docker"` instead.

**Attributes:**

* `validation_fn`: The validation
  function attached to this requirement; always non-`None`.

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />
