> ## 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.formatters.granite.base.types

> Common Pydantic types shared across the Granite formatter package.

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

Common Pydantic types shared across the Granite formatter package.

Defines reusable Pydantic models and mixins, including `NoDefaultsMixin` (which
suppresses unset default fields from serialized JSON output) and message/request
types for Granite model chat completions (`ChatMessage`, `ChatCompletion`,
`VLLMExtraBody`, `ChatCompletionLogProbs`, and related classes). These types are
consumed internally by the Granite intrinsic formatters.

## 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> `NoDefaultsMixin` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L21" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Avoid filling JSON with default values.

Mixin so that we don't need to copy and paste the code to avoid filling JSON values
with a full catalog of the default values of rarely-used fields.

<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> `UserMessage` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L129" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

User message for an IBM Granite model chat completion request.

**Attributes:**

* `role`: Always `"user"`, identifying the message sender.

<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> `DocumentMessage` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L139" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Document message for Granite model chat completion.

Document message for an IBM Granite model (from the Ollama library) chat
completion request.

**Attributes:**

* `role`: A string matching the pattern `"document <name>"`,
  identifying this message as a document fragment.

<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> `ToolCall` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L153" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Represents a single tool-call entry produced by an assistant message.

Captures the identifier, name, and arguments of a tool invocation returned
by the model during a chat completion response.

**Attributes:**

* `id`: An optional unique identifier for this tool call,
  used to correlate calls with their results.
* `name`: The name of the tool to invoke.
* `arguments`: A mapping of argument names to
  values, conforming to the parameter schema of the associated tool
  definition.

<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> `AssistantMessage` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L176" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Assistant message for chat completion.

Lowest-common-denominator assistant message for an IBM Granite model chat
completion request.

**Attributes:**

* `role`: Always `"assistant"`, identifying the message sender.
* `tool_calls`: Optional list of tool calls
  requested by the assistant during this turn.
* `reasoning_content`: Optional chain-of-thought or reasoning
  text produced by the model before the final response.

<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> `ToolResultMessage` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L195" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Tool result message from chat completion.

Message containing the result of a tool call in an IBM Granite model chat completion
request.

**Attributes:**

* `role`: Always `"tool"`, identifying this as a tool-result message.
* `tool_call_id`: The identifier of the tool call this message responds to.

<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> `SystemMessage` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L210" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

System message for an IBM Granite model chat completion request.

**Attributes:**

* `role`: Always `"system"`, identifying this as a system-level instruction.

<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> `DeveloperMessage` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L220" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Developer system message for a chat completion request.

**Attributes:**

* `role`: Always `"developer"`, identifying this as a developer-role message.

<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> `ToolDefinition` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L242" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

An entry in the `tools` list in an IBM Granite model chat completion request.

**Attributes:**

* `name`: The name used to identify and invoke the tool.
* `description`: An optional human-readable description of
  what the tool does.
* `parameters`: An optional JSON Schema object
  describing the tool's input parameters.

<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> `Document` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L261" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

RAG document for retrieval.

RAG documents, which in practice are usually snippets drawn from larger
documents.

**Attributes:**

* `text`: The textual content of the document snippet.
* `title`: An optional title for the document.
* `doc_id`: An optional string identifier for the document,
  required by some backends such as vLLM.

<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> `ChatTemplateKwargs` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L281" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Keyword arguments for chat template.

Values that can appear in the `chat_template_kwargs` portion of a valid chat
completion request for a Granite model.

**Attributes:**

* `model_config`: Pydantic model configuration allowing
  arbitrary types and extra fields to be passed through to
  model-specific I/O processors.

<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> `VLLMExtraBody` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L301" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Extra body parameters for vLLM API.

Elements of `vllm.entrypoints.openai.protocol.ChatCompletionRequest` that
are not part of OpenAI's protocol and need to be stuffed into the
"extra\_body" parameter of a chat completion request.

**Attributes:**

* `documents`: RAG documents made accessible to
  the model during generation, if the template supports RAG.
* `add_generation_prompt`: When `True`, the generation prompt is
  appended to the rendered chat template. Defaults to `True`.
* `chat_template_kwargs`: Additional keyword
  arguments forwarded to the chat template renderer.
* `structured_outputs`: Optional JSON schema that constrains
  the model's output format.

<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> `ChatCompletion` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L367" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Chat completion request schema.

Subset of the schema of a chat completion request in vLLM's OpenAI-compatible
inference API that is exercised by Granite models.

See the class `vllm.entrypoints.openai.protocol.ChatCompletionRequest` for
more information.

**Attributes:**

* `messages`: The ordered list of chat messages forming
  the conversation history.
* `model`: An optional model identifier specifying which model
  to use for the completion.
* `tools`: An optional list of tool
  definitions made available to the model during generation.
* `extra_body`: Optional vLLM-specific parameters
  not covered by the OpenAI protocol, such as documents and
  chat-template kwargs.

<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> `GraniteChatCompletion` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L423" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Granite chat completion request.

Lowest-common-denominator inputs to a chat completion request for an IBM Granite
model.

<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> `Logprob` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L493" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Prompt log-probability from vLLM API.

Subset of the vLLM API passing **prompt** log-probabilities back from vLLM's
OpenAI-compatible server.

Note that this is different from the API for token logprobs.

See the class `vllm.entrypoints.openai.protocol.Logprob` for
more information.

**Attributes:**

* `logprob`: The log-probability value for this token.
* `rank`: The rank of this token among the top candidates,
  if available.
* `decoded_token`: The decoded string representation of the
  token, if available.

<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> `ChatCompletionLogProb` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L517" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Token log-probability from vLLM API.

Subset of the vLLM API passing **token** log-probabilities back from vLLM's
OpenAI-compatible server.

Note that this is different from the API for prompt logprobs.

See the class `vllm.entrypoints.openai.protocol.ChatCompletionLogProb` for
more information.

**Attributes:**

* `token`: The decoded token string.
* `logprob`: The log-probability of the token. Defaults to
  `-9999.0` when not returned by the server.
* `bytes`: The UTF-8 byte values of the token,
  if provided by the server.

<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> `ChatCompletionLogProbsContent` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L541" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Token log-probabilities content from vLLM API.

Subset of the vLLM API passing token log-probabilities back from vLLM's
OpenAI-compatible server.

See the class `vllm.entrypoints.openai.protocol.ChatCompletionLogProbsContent` for
more information.

**Attributes:**

* `top_logprobs`: The list of top-k
  candidate tokens and their log-probabilities at this position.

<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> `ChatCompletionLogProbs` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L558" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Token logprobs for chat completion choice.

Subset of the schema of a token logprobs for a single choice in a chat completion
result in vLLM's OpenAI-compatible inference API.

See the class `vllm.entrypoints.openai.protocol.ChatCompletionLogProbs` for
more information.

**Attributes:**

* `content`: Per-token
  log-probability entries for each generated token, or `None` if
  logprobs were not requested.

<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> `ChatCompletionResponseChoice` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L576" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Single choice in chat completion result from vLLM API.

Subset of the schema of a single choice in a chat completion result in vLLM's
OpenAI-compatible inference API that is exercised by Granite intrinsics.

See the class `vllm.entrypoints.openai.protocol.ChatCompletionResponseChoice` for
more information.

**Attributes:**

* `index`: The zero-based index of this choice in the response.
* `message`: The generated message for this choice.
* `logprobs`: Token log-probabilities for
  this choice, if they were requested.
* `finish_reason`: The reason the model stopped generating.
  Defaults to `"stop"` per the OpenAI specification.

<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> `ChatCompletionResponse` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/formatters/granite/base/types.py#L601" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Chat completion result from vLLM API.

Subset of the schema of a chat completion result in vLLM's OpenAI-compatible
inference API that is exercised by Granite intrinsics.

See the class `vllm.entrypoints.openai.protocol.ChatCompletionResponse` for
more information.

**Attributes:**

* `choices`: The list of generated
  response choices returned by the model.
* `prompt_logprobs`: Per-token
  prompt log-probabilities returned by vLLM, if requested. This
  field is not part of the OpenAI specification.
* `model_config`: Pydantic configuration allowing extra fields
  to be passed through when transforming data.

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