Repository navigation
fix(prompts): stop suggestion refresh failing on high-volume estimates - #480
Merged
Merged
Conversation
The refresh endpoint's generateObject schema capped estVolume at 100000,
but the prompt feeds the model the brand's real tracked volumes and asks
it to calibrate against them — on high-volume brands it legitimately
estimates six figures, one over-cap value made zod reject the ENTIRE
batch ("No object generated: response did not match schema"), and the
failure repeated deterministically on every retry.
Drop the schema ceiling and clamp at the insert site instead (one absurd
estimate caps out rather than sinking the batch), and wrap the call in
the #379 withRetry pattern the onboarding suggestion endpoint already
uses, so genuinely transient schema misses get a second sample.
Verified against the production code path with a real brand context:
failed 100% before (suggestions[3].estVolume=112800 > 100000), succeeds
consistently after.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Generating prompt suggestions from the Prompts page failed with "No object generated: response did not match schema." — reproducibly, on every attempt.
Root cause: the refresh endpoint's
generateObjectschema cappedestVolumeat.max(100000). The generation prompt shows the model the brand's real tracked volumes and explicitly asks it to calibrate estimates against them — so on a brand with high tracked volumes the model legitimately returns six-figure estimates. One over-cap value makes zod reject the entire batch, and because the calibration instruction reproduces the same magnitudes every time, the failure is deterministic (reproduced against the production code path with a real brand context:suggestions[3].estVolume = 112800 > 100000— the other 7 suggestions were fine and the JSON was valid).Fix:
.max(100000)ceiling from the schema; out-of-range protection is now aMath.min(estVolume, 10_000_000)clamp at the insert site — one absurd estimate caps out instead of sinking the whole batch.generateObjectcall in the boundedwithRetry(3 attempts) that the onboarding suggestion endpoint already uses (Onboarding: retry LLM suggestion calls, then fall back to manual entry when they fail #379 pattern), so genuinely transient schema misses — short reason, missing item — get a fresh sample instead of failing the request.Verified with the same context that failed before: two consecutive runs both return 8 valid suggestions.
Related issue
None — reported from local testing.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
/dashboard/prompts, expand the Prompt Suggestions card and hit Refresh.est_volumevalues are plausible (clamped at 10M as a sanity bound).Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)