Robots Atlas>ROBOTS ATLAS

Prompt Engineering in Practice ยท Structured Outputs and Function Calling

Grammars, GBNF and retry-on-invalid

Structured Outputs and Function Calling

Introduction

Constrained decoding beyond cloud strict mode: GBNF in llama.cpp, FSM in Outlines, regex and grammars for non-JSON outputs (SQL, DSL). Expressivity hierarchy: regex < JSON Schema < CFG. Retry-on-invalid as last-resort defence: how to construct error messages for self-correction, when retry signals a bad schema. Defence in depth: strict mode + Pydantic + retry. Structured CoT, self-consistency, LLM-as-judge. Trade-offs of latency vs reliability, when NOT to use constrained decoding. Schema migration v1 โ†’ v2.