A stockroom tool sorts product notes into hardware, stationery, and needs_review. Pass a JSON schema through Ollama's format option when calling the local chat endpoint. Define an object with one required property, label, and give it the three values as an enum. Set additionalProperties to false if downstream code expects only that field. Use stream: false while testing so your client can read a single response.

The assistant message contains the generated content. Parse it as JSON and validate it in your application with the same schema before routing a note. Record a parse failure or validation failure and send that record for manual review. Try one note for a box of screws and another that says miscellaneous items. The first has evidence for hardware. The second needs a prompt rule that permits needs_review when the item is unclear.

Verify the meaning of a valid label

A validated stationery response for the screws is still a classification mistake. Before wiring the result to an inventory update, keep a small labeled fixture and check its decisions separately from schema validation. Add a note that mentions a notebook and a screwdriver together to test the review rule.

Exercise the validator with three fixed responses

Pass these generated-content examples directly into the same parser and schema validator used by the application. This checks your fallback even when Ollama consistently honors the schema.

  1. {"label":"hardware"} should pass and reach the hardware routing step.
  2. {"label":"other"} should fail the enum check and enter the manual review queue.
  3. {"label": should fail JSON parsing and enter the same queue with a useful error reason.

Then send real fixture notes to Ollama. Record contract failures and incorrect labels separately. For the mixed notebook and screwdriver note, require the output to pass validation with needs_review if that is your prompt’s stated rule.

Sources