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)
Bases: object
Represents the response format specification for a text generation request.
-
Parameters:
grammar
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
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
Whether this request includes a JSON schema response format.
json_schema
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
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
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
The type of response format, for example, json_object or grammar.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!