rw-book-cover

Metadata

Highlights

  • Ollama now supports structured outputs making it possible to constrain a model’s output to a specific format defined by a JSON schema. The Ollama Python and JavaScript libraries have been updated to support structured outputs. (View Highlight)
  • The response is returned in the format defined by the JSON schema in the request. (View Highlight)
  • Using the Ollama Python library, pass in the schema as a JSON object to the format parameter as either dict or use Pydantic (recommended) to serialize the schema using model_json_schema(). (View Highlight)
  • Structured outputs can also be used with vision models. For example, the following code uses llama3.2-vision to describe the following image and returns a structured output: (View Highlight)
  • For reliable use of structured outputs, consider to: • Use Pydantic (Python) or Zod (JavaScript) to define the schema for the response • Add “return as JSON” to the prompt to help the model understand the request • Set the temperature to 0 for more deterministic output (View Highlight)