Skip to content

Wire up dead Zod schemas for LLM output validation (vibe-kanban)#13

Merged
Binaryzero merged 3 commits into
masterfrom
vk/d563-wire-up-dead-zod
May 19, 2026
Merged

Wire up dead Zod schemas for LLM output validation (vibe-kanban)#13
Binaryzero merged 3 commits into
masterfrom
vk/d563-wire-up-dead-zod

Conversation

@Binaryzero

Copy link
Copy Markdown
Owner

src/analyzer/schemas.ts defines AssessmentSchema, BatchAssessmentSchema, and others with full Zod validation. This file is effectively dead code — both llm.ts and llm-batch.ts use manual JSON.parse() with duck-typing fallbacks (obj.riskLevel || obj.risk_level || ...) instead.\n\nThe providers already expose generateObject<T>(schema, ...) for structured output validated at the SDK level, but this is never used for assessments.\n\nFix: replace the manual JSON parsing in both files with AssessmentSchema.parse() to catch malformed LLM output reliably and eliminate the duck-typing chains.

Binaryzero and others added 2 commits May 16, 2026 23:48
Replaces manual JSON.parse + duck-typing chains (obj.riskLevel ||
obj.risk_level || ...) with LlmAssessmentSchema.parse() in three of
four parse sites. Adds a transform on the schema to centralize the
snake_case to camelCase mapping into LlmAssessment shape.

Triage batch site (llm.ts) left with TODO(human) for indexed variant.

Tests updated: removed camelCase-tolerance test and lenient-defaults
test that contradicted the new strict validation.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Completes the schema rollout — replaces the final duck-typed parse
loop in triageBatchAssess with IndexedLlmAssessmentSchema.safeParse().

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces manual JSON parsing and mapping with type-safe Zod schema validation for LLM assessments. It introduces LlmAssessmentSchema and IndexedLlmAssessmentSchema to handle the transformation from snake_case wire format to internal camelCase types, simplifying the logic in llm-batch.ts and llm.ts. Tests were updated to reflect stricter validation requirements. A review comment suggests refactoring the schema transformations to reduce code duplication by extracting a shared mapping function.

Comment thread src/analyzer/schemas.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 057ffba4ed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/analyzer/llm.ts
Codex P1: schema rejected `false_positive_reason: null`, which
prompts.yaml lines 40 and 432 explicitly allow. Coerce null/undefined
to '' via .nullable().optional().transform() so prompt-compliant LLM
output isn't silently dropped.

Gemini: factored the snake_case -> camelCase mapping into a shared
mapToInternal() helper consumed by both LlmAssessmentSchema and
IndexedLlmAssessmentSchema, eliminating the duplicated transform body.

Added a regression test asserting null false_positive_reason parses
to ''. 214/213 tests passing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Binaryzero Binaryzero merged commit fabc922 into master May 19, 2026
@Binaryzero Binaryzero deleted the vk/d563-wire-up-dead-zod branch May 19, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant