Python class
TextGenerationResponseFormat
TextGenerationResponseFormat
class max.pipelines.modeling.types.pipeline_variants.TextGenerationResponseFormat
Bases: TypedDict
Represents the response format specification for a text generation request.
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
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.
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: NotRequired[bool]
Whether this request requires --enable-structured-output to be set.
True when the constraint includes a user-supplied JSON schema (from
response_format). False (or absent) 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.
Optional (defaults to False) so existing call sites that construct
TextGenerationResponseFormat directly don’t need to be updated.
tools_forced
tools_forced: bool
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!