vllm.reasoning.cohere_command_reasoning_parser ¶
Classes:
-
CohereNormalizedTool–A tool definition normalized to the shape
collect_tool_schemaexpects. -
CohereTagRegistry–A single
structural_tagtrigger / end pair (beginusestrigger). -
CohereTagStyle–The structural tags style for a given model architecture.
Functions:
-
collect_tool_schema–Build an xgrammar EBNF grammar that matches a JSON array of tool calls.
-
convert_schema_to_structural_tags–Returns a response_format string accepted by xgrammar's structural tag format.
CohereNormalizedTool ¶
Bases: TypedDict
A tool definition normalized to the shape collect_tool_schema expects.
parameters is a JSON Schema object (possibly empty) describing the tool's call signature.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
CohereTagRegistry ¶
Bases: NamedTuple
A single structural_tag trigger / end pair (begin uses trigger).
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
CohereTagStyle ¶
Bases: NamedTuple
The structural tags style for a given model architecture.
json_tags lists every JSON-schema wrapper the model may emit (MOE uses both response and text delimiters). tools is the tool-call wrapper.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_has_effective_tools(tools) ¶
True when tools contains at least one tool definition to convert.
ResponsesRequest defaults tools to []; ChatCompletionRequest uses None. Both mean "no tools" here. Strings (e.g. a JSON blob) are treated as effective only when non-blank.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_maybe_parse_json_dict(value) ¶
If value is a JSON string, parse to dict; otherwise require dict.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_schema_dict_from_chat_response_format(rf) ¶
JSON schema dict from Chat Completions request.response_format only.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_schema_dict_from_structured_outputs(so) ¶
Schema dict from structured_outputs (json / json_object).
Same unwrapping as json_schema. json is expected to be str or dict (enforced by StructuredOutputsParams / request models); other types raise ValueError only if a caller bypasses that validation.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_schema_from_json_schema_field(js_wr) ¶
Extract the JSON Schema object from Chat Completions json_schema payload.
Accepts: - JsonSchemaResponseFormat (Pydantic) with schema / json_schema field - dict in OpenAI shape {"name": ..., "schema": {...}} - dict with json_schema key holding either the schema or a nested wrapper - dict that is already a JSON Schema document (some clients omit the wrapper) - JSON strings for any of the above
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_tool_definitions_to_schema_list(tools) ¶
Build the list of CohereNormalizedTool dicts expected by collect_tool_schema.
Accepts: - JSON string - list of dicts with top-level name / parameters - list of Chat Completions-style {"type": "function", "function": {...}} - list of Pydantic models with model_dump()
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_unwrap_nested_schema(candidate) ¶
Return candidate as a dict, unwrapping a nested schema if present.
Returns None if candidate is not (and cannot be parsed into) a dict.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
collect_tool_schema(tool_schema) ¶
Build an xgrammar EBNF grammar that matches a JSON array of tool calls.
The grammar shape is architecture-independent; callers are responsible for wrapping it in the correct structural tag (see CohereTagStyle.tools).
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
convert_schema_to_structural_tags(schema=None, tools=None, model_architecture=None) ¶
Returns a response_format string accepted by xgrammar's structural tag format. Uses the canonical shape: {"type": "structural_tag", "format": {...}} with format.type "triggered_tags" and tag content type "json_schema" or "grammar".
Callers that are not on an engine path (e.g. the reasoning parser) must pass model_architecture explicitly.