Structured Outputs with Ollama

Ollama, as of December 6, 2024, now supports structured outputs, allowing for specific format constraints based on a JSON schema with updated Python and JavaScript libraries. Use cases include parsing data from documents, extracting data from images, and ensuring more reliability and consistency than JSON mode. To implement structured outputs, one can update to the latest Ollama version and use the format parameter in cURL requests or Python and JavaScript libraries. Pydantic (Python) and Zod (JavaScript) are recommended for defining schemas. Examples include data extraction and image description. Tips for optimal use include returning results as JSON and setting the temperature to 0 for deterministic output.Future plans include exposing logits for controlled generation, improved performance and accuracy, GPU acceleration for sampling, and expanded format support beyond JSON schema.

https://ollama.com/blog/structured-outputs

To top