> ## 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.stdlib.requirements.tool_reqs

> [`Requirement`](../../core/requirement#class-requirement) factories for tool-use 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 />

[`Requirement`](../../core/requirement#class-requirement) factories for tool-use validation.

Provides `uses_tool`, a [`Requirement`](../../core/requirement#class-requirement) factory that validates whether a model
response includes a call to a specified tool — useful when you need to enforce tool
invocation via rejection sampling rather than relying solely on the model's
`tool_choice` setting. Also provides `tool_arg_validator`, which validates the
value of a specific argument to a named tool. Both accept either the tool's string
name or its callable.

## Functions

<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-[#3064E3]/20 text-[#1D4ED8]">FUNC</span> `uses_tool` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/stdlib/requirements/tool_reqs.py#L26" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
uses_tool(tool_name: str | Callable, check_only: bool = False) -> Requirement
```

Forces the model to call a given tool.

**Args:**

* `tool_name`: The tool that must be called; this can be either the name of the tool or the Callable for the tool.
* `check_only`: Propagates to the Requirement.

Use `tool_choice` if the OpenAI `tool_choice` model option is supported by your model and inference engine.

**Returns:**

* A [`Requirement`](../../core/requirement#class-requirement) that validates whether the specified tool was called.

<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-[#3064E3]/20 text-[#1D4ED8]">FUNC</span> `tool_arg_validator` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/stdlib/requirements/tool_reqs.py#L54" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
tool_arg_validator(description: str, tool_name: str | Callable | None, arg_name: str, validation_fn: Callable, check_only: bool = False) -> Requirement
```

A requirement that passes only if `validation_fn` returns a True value for the *value* of the `arg_name` argument to `tool_name`.

If `tool_name` is not specified, then this requirement is enforced for *every* tool that was called.

**Args:**

* `description`: The Requirement description.
* `tool_name`: The (optional) tool name to validate. When None, all tools are checked.
* `arg_name`: The argument to check.
* `validation_fn`: A validation function for validating the value of the `arg_name` argument.
* `check_only`: propagates the `check_only` flag to the requirement.

**Returns:**

* A [`Requirement`](../../core/requirement#class-requirement) that validates the specified tool argument.

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