Model wrapper that returns outputs formatted to match the given schema.
with_structured_output(
self,
schema: Optional[Union[Dict, Type[BaseModel]]] = None,
*,
method: Literal['function_calling', 'json_mode'] = 'function_calling',
include_raw: bool = False,
**kwargs: Any = {}
) -> Runnable[LanguageModelInput, Union[Dict, BaseModel]]| Name | Type | Description |
|---|---|---|
schema | Optional[Union[Dict, Type[BaseModel]]] | Default: NoneThe output schema as a dict or a Pydantic class. If a Pydantic class
then the model output will be an object of that class. If a dict then
the model output will be a dict. With a Pydantic class the returned
attributes will be validated, whereas with a dict they will not be. If
|
method | Literal['function_calling', 'json_mode'] | Default: 'function_calling'The method for steering model generation, either "function_calling" or "json_mode". If "function_calling" then the schema will be converted to an OCI function and the returned model will make use of the function-calling API. If "json_mode" then Cohere's JSON mode will be used. Note that if using "json_mode" then you must include instructions for formatting the output into the desired schema into the model call. |
include_raw | bool | Default: FalseIf If an error occurs during model output parsing it will be raised. If If an error occurs during output parsing it will be caught and returned as well. The final output is always a |