Skip to content

fix(ai): default series type to event in funnel report tool#328

Open
nielskaspers wants to merge 1 commit intoOpenpanel-dev:mainfrom
nielskaspers:fix/issue-327-funnel-series-type
Open

fix(ai): default series type to event in funnel report tool#328
nielskaspers wants to merge 1 commit intoOpenpanel-dev:mainfrom
nielskaspers:fix/issue-327-funnel-series-type

Conversation

@nielskaspers
Copy link
Copy Markdown

@nielskaspers nielskaspers commented Apr 3, 2026

Summary

  • Adds a z.preprocess wrapper around the zChartEventItem discriminated union to default type to "event" when the field is missing
  • Prevents Zod invalid_union_discriminator errors when the LLM omits the type field in series objects during AI chat funnel report generation

Issue

Fixes #327

Changes

  • packages/validation/src/index.ts: Wrapped zChartEventItem with z.preprocess() that adds type: "event" to objects missing the type field before discriminated union validation

Testing

  • Ask the AI chat to generate a funnel report
  • Verify the tool call succeeds even if the LLM omits type in series objects
  • Verify that explicitly passing type: "event" or type: "formula" still works as before

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced chart event validation to automatically handle inputs without explicit type specifications, reducing validation errors and improving data compatibility for chart operations.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 3, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b0c124a0-863f-4761-80ef-a87e3b3c9b00

📥 Commits

Reviewing files that changed from the base of the PR and between a1ce71f and a06a2f1.

📒 Files selected for processing (1)
  • packages/validation/src/index.ts

📝 Walkthrough

Walkthrough

Modified the zChartEventItem schema to automatically inject the missing type: 'event' discriminator field during preprocessing when the field is absent from incoming objects, enabling validation of incomplete event item payloads.

Changes

Cohort / File(s) Summary
Validation Schema Preprocessing
packages/validation/src/index.ts
Added preprocessing wrapper to zChartEventItem that auto-injects type: 'event' for objects missing the discriminator field before passing to discriminated union validation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A little injection of type, so swift,
When 'event' goes missing, we give it a gift,
No more validation wails and sighs—
The AI chat now soars through the skies! 🚀✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: defaulting the series type to 'event' in the funnel report tool via the z.preprocess wrapper applied to zChartEventItem.
Linked Issues check ✅ Passed The PR implements the third suggested fix from issue #327 by adding a z.preprocess wrapper that defaults missing 'type' to 'event' before validation, directly addressing the LLM omission problem.
Out of Scope Changes check ✅ Passed All changes are scoped to the zChartEventItem schema modification, directly implementing the proposed default fallback fix without introducing unrelated alterations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

AI Chat: getFunnelReport tool calls fail with AI_InvalidToolArgumentsError (missing series type discriminator)

2 participants