Skip to content

fix(looker): validate explore_references shape instead of panicking#3531

Merged
drstrangelooker merged 1 commit into
googleapis:mainfrom
he-yufeng:fix/looker-ca-explore-refs-validation
Jun 26, 2026
Merged

fix(looker): validate explore_references shape instead of panicking#3531
drstrangelooker merged 1 commit into
googleapis:mainfrom
he-yufeng:fix/looker-ca-explore-refs-validation

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

What

looker-conversational-analytics parses the explore_references tool parameter with chained, unchecked type assertions:

LookmlModel: er.(map[string]any)["model"].(string),
Explore:     er.(map[string]any)["explore"].(string),

explore_references is declared as an array of free-form maps (NewMapParameter with an empty value type), so the entries a model supplies are never schema-validated. Each of these shapes panics the tool instead of returning an error the model can act on:

  • an element that isn't an object (e.g. a bare string)
  • a missing model or explore key
  • a non-string model / explore value

Models drop or mistype those fields often enough that this is reachable in normal use, and panicking inside Invoke is a poor failure mode for a hallucinated argument.

Fix

Move the parsing into a small parseExploreReferences helper that validates each element and field and returns a clear util.NewAgentError, mirroring the validation already done in datalineagesearchlineage. Behaviour for valid input is unchanged.

Tests

Added TestParseExploreReferences covering valid references, nil/empty input, and the five malformed shapes above. With the helper removed the package no longer builds (the test references it), and with the fix go test ./internal/tools/looker/lookerconversationalanalytics/ passes. go build ./..., go vet, and gofmt are clean.

The looker-conversational-analytics tool read explore_references with
chained, unchecked type assertions:

    LookmlModel: er.(map[string]any)["model"].(string),
    Explore:     er.(map[string]any)["explore"].(string),

explore_references is declared as an array of free-form maps
(NewMapParameter with an empty value type), so the entries the model
supplies are never schema-validated. A reference that is not an object,
omits "model"/"explore", or carries a non-string value, panics the tool
on the type assertion rather than returning a usable error. Models drop
or mistype those fields often enough that this is reachable in normal
operation.

Move the parsing into a small helper that checks each element and field
and returns a clear agent error, matching the validation already done in
datalineagesearchlineage. Add unit tests covering the valid, empty, and
malformed cases.

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
@he-yufeng he-yufeng requested review from a team as code owners June 25, 2026 23:53

@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 introduces a new helper function parseExploreReferences to safely parse the explore_references parameter in the Looker Conversational Analytics tool. This replaces direct type assertions with proper type checking and validation to prevent potential panics from unexpected shapes. Additionally, a comprehensive suite of unit tests has been added in lookerconversationalanalytics_internal_test.go to cover valid inputs, nil inputs, and various error scenarios. There are no review comments, and I have no feedback to provide.

@drstrangelooker

Copy link
Copy Markdown
Contributor

/gcbrun

@drstrangelooker

Copy link
Copy Markdown
Contributor

/gcbrun

@drstrangelooker drstrangelooker merged commit b67419d into googleapis:main Jun 26, 2026
20 checks passed
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.

3 participants