open-mercato
“The fix was to pre-generate compact TypeScript type stubs from the OpenAPI spec at startup and inject them directly into the tool description (mirroring Cloudflare's pattern), so the LLM sees the correct schema inline immediately instead of guessing, eliminating the malformed-payload debug spirals.”
team — open-mercato
Why they built it
The team shipped an AI Code Mode into their open-source commerce platform so an LLM could construct and execute structured API calls against the platform's own search and execute tools, letting operators drive commerce workflows through natural language instead of hand-writing API payloads.
What worked
- ✓The platform exposes search and execute tools to the LLM over a multi-tenant Node/Next.js stack with MikroORM and PostgreSQL, and the team captured the failure mode in an .ai/lessons.md so the fix generalizes to any LLM-facing tool that builds structured calls.
What broke or was painful
- ✗Because the LLM had to query a separate tool to discover schema fields and then mentally translate a compact JSON format, it frequently constructed wrong payloads, got 400 errors, and entered debug spirals of 20-plus tool calls and 50-plus API requests per task, burning time and tokens guessing at field names it could not see.
The result
The fix was to pre-generate compact TypeScript type stubs from the OpenAPI spec at startup and inject them directly into the tool description (mirroring Cloudflare's pattern), so the LLM sees the correct schema inline immediately instead of guessing, eliminating the malformed-payload debug spirals.
What they'd do differently
For any LLM-facing tool that constructs structured API calls, embed the schema as inline TypeScript types in the tool description rather than forcing the model to discover fields through extra tool round-trips.