JSON Schema
What is
JSON Schema — a format for describing the structure of JSON: which fields are allowed, their types, and their required status. It allows for validating data before processing.
Relation to Structured Output
When a strict JSON response is needed from an LLM (rather than 'decorated' text), a combination of a system prompt to return 'strict JSON', a low temperature, and parsing the response helps. More details in the case study on the meta-tag generator.
preg_match('/\{[\s\S]*\}/', $raw, $m);
$meta = json_decode($m[0] ?? '', true);
if (!is_array($meta)) { $meta = ['raw' => $raw]; }