Skip to content

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

@vkuprin

Description

@vkuprin

Description

The AI chat feature consistently fails when attempting to generate funnel reports (and likely other chart types). The LLM calls getFunnelReport but omits the required type discriminator field in series objects, causing Zod validation to reject every tool call.

Error

AI_InvalidToolArgumentsError → AI_TypeValidationError → ZodError
{
  "code": "invalid_union_discriminator",
  "options": ["event", "formula"],
  "path": ["series", 0, "type"],
  "message": "Invalid discriminator value. Expected 'event' | 'formula'"
}

What the LLM sends

{
  "series": [
    { "name": "screen_view", "displayName": "Page View" },
    { "name": "signup_completed", "displayName": "Signup Completed" }
  ]
}

What the schema expects

{
  "series": [
    { "type": "event", "name": "screen_view", "displayName": "Page View" },
    { "type": "event", "name": "signup_completed", "displayName": "Signup Completed" }
  ]
}

Impact

  • The AI chat is effectively broken for any analytical query that requires tool calls
  • The error loops silently — the user sees repeated "An error occurred" messages with no useful feedback
  • finishReason: "tool-calls" confirms the LLM is trying to call tools but they all fail validation

Reproduction

  1. Open AI chat in the OpenPanel dashboard
  2. Ask something like "Show me a funnel report for screen_view → signup_completed"
  3. The AI attempts a tool call, Zod rejects it, and "An error occurred" is returned

Suggested fix

The LLM isn't being told about the required type field in series objects. Either:

  1. Add explicit examples in the system prompt showing "type": "event" in series objects
  2. Ensure the full Zod schema (including the discriminated union) is passed to the model's tool definitions
  3. Add a default type: "event" fallback in the tool argument parser before Zod validation

Environment

  • OpenPanel version: 2.2.1 (lindesvard/openpanel-api:2)
  • Self-hosted via Coolify

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions