Rules Hub
Code Ruleset
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: node
llmschemapromptscorrectness
Keep validation constraints consistent with what the LLM is told to produce
If a schema caps a field length, the prompt must instruct the model to stay within that cap; otherwise valid model output fails parsing.
PR: hegnar-journalist-boost · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const schema = z.object({ reasoning: z.string().max(240) }); |
| 2 | // prompt never tells the model to keep reasoning under 240 chars |
Explanation (EN)
Unstated output limits cause avoidable validation failures even for otherwise relevant responses.
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const schema = z.object({ reasoning: z.string().max(240) }); |
| 2 | const PROMPT = 'Explain your choice in at most 240 characters.'; |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
When a model output schema has a field limit, include the same constraint in generation instructions and validate the actual response independently.
Exceptions / Tradeoffs (EN)
Prompt compliance is not guaranteed; handle invalid output with a defined retry or failure path rather than bypassing validation.