Getting the LLM to consistently emit valid filter and ranking plans as structured JSON — without hallucinating fields or breaking the downstream tool calls.
Solution
Used AI SDK's structured output mode with strict Zod schemas for both the filter plan and ranking plan. Any schema violation triggers a retry with an error-context prompt, keeping the pipeline deterministic.
