A language model can produce well-formed JSON that still violates business rules. Syntax validity, schema validity and semantic correctness are distinct checks.
Implementation approach
Define a narrow output schema with required fields and allowed values. Validate responses at runtime and reject unknown identifiers or unsupported actions before passing output to downstream systems.
Example
type Decision = { action: 'review' | 'skip'; reason: string };
Validation and edge cases
Test malformed JSON, unsupported actions and plausible but incorrect identifiers. Use bounded retries for formatting failures and route ambiguous or consequential decisions to manual review.
Key takeaway
Never let generated instructions directly trigger arbitrary commands or bypass permissions.




