If another system must consume it, structure it
Chat prose is for humans. If Laravel must create a ticket, set a priority, and assign a queue, ask the model for JSON that matches a schema.
Pattern
- Define a schema (fields, enums, required)
- Request structured output / tool call
- Validate; retry with the validator errors once
- Only then write to the database
When freeform still wins
Brainstorming, long explanations, and agent-facing drafts. Even then, you can ask for sections with headings to make editing easier.
Failure handling
Never parse JSON with optimism alone. Invalid output should become a user-visible retry, not a 500 for the whole form submit.
This discipline is how Rayaxis keeps practical AI features maintainable beside normal application code.