Meridian Recipe
Rails primer
Recipe rails are deterministic guard tracks that wrap an LLM call so the output lands inside a contract you control. This primer walks through the three rails every Meridian production recipe ships with, and shows the minimum wiring to invoke them from a server route.
1.Schema rail
The schema rail forces the model to emit JSON that matches a JSON Schema you declare alongside the prompt. Meridian retries up to three times with the validator error appended to the system message, then surfaces a typed failure instead of garbage. Use this when downstream code parses the result.
2.Budget rail
Every recipe carries a token + dollar ceiling. The budget rail aborts the call the instant cumulative usage crosses the ceiling, even mid-stream, and emits a structured overage event so your billing and alerting stay honest. Default to a 1.5x ceiling over your p99 measured cost.
3.Fallback rail
When the primary model errors, times out, or fails schema three times, the fallback rail re-routes to a sibling model you nominated at recipe-create time. The client never sees a 5xx unless every rail in the chain is exhausted.
Minimum wiring
A single POST to /v1/recipes/run activates all three rails for a published recipe slug:
curl https://api.meridian.dev/v1/recipes/run \
-H "Authorization: Bearer $MERIDIAN_KEY" \
-H "Content-Type: application/json" \
-d '{
"recipe": "extract-invoice-v3",
"input": { "pdf_url": "https://..." },
"budget_usd": 0.05
}'