fix(flaggers): stop classifier structured-output truncation at max tokens - #3910
Merged
Conversation
…kens Bedrock Haiku flagger classify calls were hitting the 2048-token output limit with truncated JSON (matched + messageIndex, no feedback), which surfaced as the structured-output JSON parse failure signal. Drop messageIndex from the provider schema so classify output is only matched + feedback, and lower the classifier maxTokens default to 512. Co-authored-by: Gerard <gerard@latitude.so>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Re-introduce messageIndex in the classifier structured output, but rebuild the generation schema per classify call so messageIndex is a z.enum of the trace's real transcript indices instead of an open-ended numeric string. The runaway that truncated output at the token cap came from messageIndex being length-unbounded under Bedrock/Anthropic object generation: at temperature 0 the model kept emitting digits until finishReason=length, leaving invalid JSON. Enumerating the valid indices makes the field a choice among a small finite set, which the decoder cannot run away on, while preserving the message anchor in the classify result. maxTokens stays at 512 as defense in depth. Co-authored-by: Gerard <gerard@latitude.so>
Co-authored-by: Gerard <gerard@latitude.so>
geclos
marked this pull request as ready for review
July 8, 2026 08:53
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
PR #3910 — Diff ExplanationAn interactive HTML walkthrough of this PR has been published: Artifact (Cloudflare temporary): https://artifact-pr-3910-diff-review.modern-albertonykus.workers.dev Claim within 60 minutes (permanent): https://dash.cloudflare.com/claim-preview?claimToken=2gv3j_qMiSvOXEoswWAH25z2xLu5T-srlnxvkuTIn6Y The artifact covers:
|
…-json-parse-failure-1d6f * origin/development: (71 commits) Fix signup attribution across latitude.so and console boundary (#3941) chore(deps): bump astral-sh/setup-uv from 7 to 8.3.0 (#3994) chore: update bundled models.dev data (#3987) chore(deps): bump @tanstack/react-virtual (#4002) Lock monitor incident conditions after creation (#3947) chore(deps): bump @typescript/native-preview (#3989) chore(deps): bump taiki-e/install-action from 2.82.7 to 2.82.9 (#3991) chore(deps): bump typing-extensions in /packages/platform/op-gepa/python (#3992) chore(deps): bump opentelemetry-instrumentation-together (#3993) chore(deps): bump opentelemetry-instrumentation-langchain (#3995) chore(deps): bump @slack/web-api from 7.10.0 to 7.18.0 (#3996) chore(deps): bump docker/build-push-action from 7.2.0 to 7.3.0 (#3997) chore(deps): bump openinference-instrumentation-openai-agents (#3998) chore(deps): bump openinference-instrumentation-crewai (#3999) chore(deps): bump aws-actions/configure-aws-credentials (#4000) chore(deps): bump typing-extensions in /packages/telemetry/python (#4001) Fix OAuth token validation to enforce live organization membership (#3917) feat(wrapped): add skills breakdown to Claude Code Wrapped (report V3) (#3978) chore(deps): bump the npm_and_yarn group across 1 directory with 2 updates (#3902) chore(deps): bump anthropics/claude-code-action from 1.0.160 to 1.0.166 (#3990) ... # Conflicts: # packages/domain/flaggers/src/use-cases/run-flagger.test.ts
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
Fixes the escalating Structured-output JSON parse failure (flagger) signal in the Flaggers project (signal, ID
gyloub76vor6ytuq12gkj77c).Flagger classify traces on Bedrock Haiku were repeatedly ending with
finishReason: length, exactly 2048 output tokens, and truncated assistant JSON like{"matched":true,"messageIndex":"1"— missing requiredfeedbackand a closing brace. Those malformed classify traces were then picked up by the deterministic output-schema-validation flagger, generating the signal.Example traces:
d16f58bc63c9ae4de462b0adeb8484d8,ca2bacf072a8395a18de7cfa3b9be507,00e2d7778d81b2a663f7c7dd2f11e982.Root cause
The classifier structured-output
messageIndexwas an open-ended field (first a JSON number, later a^\d+$string). Neither form is length-bounded in the tool schema Bedrock/Anthropic receives, so attemperature: 0the model could get stuck emitting digits formessageIndexand never close the object — it exhausted the output budget (finishReason: length) and produced truncated, unparseable JSON. Prior work (#3369, #3377) changed the field's type but not its open-ended nature, so the same truncation kept recurring.Fix
Keep
messageIndexin the classify result, but make it structurally impossible to run away:messageIndexto an enum.buildProviderFlaggerOutputSchemais rebuilt per classify call somessageIndexis az.enumof the trace's real transcript indices as string literals (capped at 200 to stay within Bedrock's grammar-size limits; omitted when the trace has no messages). The field becomes a choice among a small finite set, which the constrained/tool decoder cannot run away on.parseFlaggerOutputrather than failing the whole classification.maxTokenslowered 2048 → 512 as defense-in-depth — the payload is a boolean plus one or two short sentences.Existing no-output / schema-mismatch handling still maps any residual failure to
matched=false.Testing
pnpm --filter @domain/flaggers test(240 pass, 2 skipped)pnpm --filter @domain/flaggers typecheckmessageIndexto the trace's indices, omits it for empty traces, and is the schema passed to the classify calld16f58bcpattern)Follow-up
Do not mute or resolve the signal until after deploy and a human verifies occurrence drop-off. A separate improvement worth considering: label each transcript line with its index in the classify prompt so the enum values map to something the model explicitly sees, improving anchor accuracy.