IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Python class

TextGenerationResponseFormat

TextGenerationResponseFormat

class max.pipelines.context.TextGenerationResponseFormat(type, json_schema=<factory>, grammar=None, grammar_enforced=False, tools_forced=False, requires_structured_output_flag=False, has_json_schema=False)

source

Bases: object

Represents the response format specification for a text generation request.

Parameters:

  • type (str)
  • json_schema (dict[str, Any])
  • grammar (str | None)
  • grammar_enforced (bool)
  • tools_forced (bool)
  • requires_structured_output_flag (bool)
  • has_json_schema (bool)

grammar

grammar: str | None = None

source

Grammar for constrained decoding.

When set with type="grammar", this takes precedence over json_schema. Used for model-specific constrained decoding formats like Kimi’s tool call grammar.

grammar_enforced

grammar_enforced: bool = False

source

Whether to actively enforce grammar via bitmask.

When True from the start, enforce grammar from the first token. When False initially (for tool_choice=auto without response_format), the grammar is compiled but not enforced until a tool call start token is detected.

has_json_schema

has_json_schema: bool = False

source

Whether this request includes a JSON schema response format.

json_schema

json_schema: dict[str, Any]

source

A JSON schema dictionary that defines the structure and validation rules for the generated response.

requires_structured_output_flag

requires_structured_output_flag: bool = False

source

Whether this request requires --enable-structured-output to be set.

True when the constraint includes a user-supplied JSON schema (from response_format). False for pure tool-call grammars derived from the model’s tool parser, which work without the operator flag because the grammar is server-controlled, not user-controlled.

tools_forced

tools_forced: bool = False

source

Whether tool calling was forced (tool_choice=required or named function).

Controls whether grammar_enforced is True from the first generated token. Independent of the --enable-structured-output flag (which only gates user-supplied schemas; see requires_structured_output_flag).

type

type: str

source

The type of response format, for example, json_object or grammar.