> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mellea.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# mellea.plugins.hooks.sampling

> Sampling pipeline hook payloads.

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 />

Sampling pipeline hook payloads.

## 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> `SamplingLoopStartPayload` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/plugins/hooks/sampling.py#L10" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Payload for `sampling_loop_start` — when sampling strategy begins.

**Attributes:**

* `strategy_name`: Class name of the sampling strategy (e.g. `"RejectionSamplingStrategy"`).
* `action`: The [`Component`](../../core/base#class-component) being sampled.
* `context`: The [`Context`](../../core/base#class-context) at the start of sampling.
* `requirements`: List of [`Requirement`](../../core/requirement#class-requirement) instances to validate against.
* `loop_budget`: Maximum number of sampling iterations allowed (writable).

<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> `SamplingIterationPayload` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/plugins/hooks/sampling.py#L30" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Payload for `sampling_iteration` — after each sampling attempt.

**Attributes:**

* `strategy_name`: Class name of the sampling strategy (e.g. `"RejectionSamplingStrategy"`).
* `iteration`: 1-based iteration number within the sampling loop.
* `action`: The [`Component`](../../core/base#class-component) used for this attempt.
* `result`: The [`ModelOutputThunk`](../../core/base#class-modeloutputthunk) produced by this attempt.
* `validation_results`: List of `(Requirement, ValidationResult)` tuples.
* `all_validations_passed`: `True` when **every** requirement in `validation_results`
  passed for this iteration (i.e., the sampling attempt succeeded).
* `valid_count`: Number of requirements that passed.
* `total_count`: Total number of requirements evaluated.

<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> `SamplingRepairPayload` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/plugins/hooks/sampling.py#L56" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Payload for `sampling_repair` — when repair is invoked after validation failure.

**Attributes:**

* `repair_type`: Kind of repair (strategy-dependent, e.g. `"rejection"`, `"template"`).
* `failed_action`: The [`Component`](../../core/base#class-component) that failed validation.
* `failed_result`: The [`ModelOutputThunk`](../../core/base#class-modeloutputthunk) that failed validation.
* `failed_validations`: List of `(Requirement, ValidationResult)` tuples that failed.
* `repair_action`: The repaired [`Component`](../../core/base#class-component) to use for the next attempt.
* `repair_context`: The [`Context`](../../core/base#class-context) to use for the next attempt.
* `repair_iteration`: 1-based iteration at which the repair was triggered.

<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> `SamplingLoopEndPayload` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/plugins/hooks/sampling.py#L79" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Payload for `sampling_loop_end` — when sampling completes.

**Attributes:**

* `strategy_name`: Class name of the sampling strategy (e.g. `"RejectionSamplingStrategy"`).
* `success`: `True` if at least one attempt passed all requirements.
* `iterations_used`: Total number of iterations the loop executed.
* `final_result`: The selected [`ModelOutputThunk`](../../core/base#class-modeloutputthunk) (best success or best failure).
* `final_action`: The [`Component`](../../core/base#class-component) that produced `final_result`.
* `final_context`: The [`Context`](../../core/base#class-context) associated with `final_result`.
* `failure_reason`: Human-readable reason when `success` is `False`.
* `all_results`: List of [`ModelOutputThunk`](../../core/base#class-modeloutputthunk) from every iteration.
* `all_validations`: Nested list — `all_validations[i]` is the list of
  `(Requirement, ValidationResult)` tuples for iteration *i*.

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