Thank you for the positive feedback! I'm glad to hear you're already using Ollama on your M1 Mac. We often underestimate what is possible on our local systems. The structured output that Ollama introduced in December is indeed impressive. I recommend using a Pydantic BaseModel to define your output, allowing Pydantic to generate the JSON Schema for you. You can then pass this schema to the Ollama chat function using the format (format=Country.model_json_schema()).
You are absolutely right that this largely depends on the LLM you are using. While structured output is supported by the usual options, I have occasionally encountered issues where it failed to generate a valid response with a simple prompt. I have had good results with Llama versions 3.1, 3.2, and 3.3, with 3.2 offering the best balance between performance and quality.
If you struggle to obtain a valid structured response, try explicitly repeating the JSON schema in your prompt (reply strictly in JSON using the following format...). For basic use cases, this approach works well, and I really enjoy the Ollama Python integration.
If I may add, I highly recommend checking out PydanticAI, a relatively new framework that recently added Ollama support. They keep things simple while offering additional features. I also just published an article about it 😉.