Skip to content

fix(tools): correct regional dimension names and clarify metric vs dimension - #108

Closed
josep-reyero wants to merge 2 commits into
mainfrom
fix/regional-dimension-names
Closed

fix(tools): correct regional dimension names and clarify metric vs dimension#108
josep-reyero wants to merge 2 commits into
mainfrom
fix/regional-dimension-names

Conversation

@josep-reyero

Copy link
Copy Markdown
Contributor

Follow-up to #107, from testing the guidance against the real dbt Semantic Layer API and a live MCP session.

A wrong dimension name shipped in #107. The organization HQ dimension is entity-prefixed — activity_project_id__organization_lf_region — not the bare organization_lf_region the tip claimed. A client copying that would build an invalid query. Verified by querying dimensionsPaginated directly and by running the grouped query end to end.

The empty-result trap. A real client session searched list_metrics for "contributor organization country" and got [], then abandoned the semantic layer entirely and fell back to the SQL agent. Measured against the API: search: "country" returns 0 metrics, "region" returns 0, "contributor" returns 2. Country and region are dimensions — they are not searchable via list_metrics by design, and nothing said so.

So this states what metrics and dimensions each are, that list_metrics matches metric names and descriptions only, and that regional dimensions come from get_dimensions on a metric found by topic.

Validated end to end against a locally built lens (main, with linuxfoundation/lfx-lens#25 and #26) through a local MCP server: discover total_contributors by topic → get_dimensions → global query grouped by country__lf_region with no project scope, returning real data.

🤖 Generated with Claude Code

…s dimension

Verified against the dbt Semantic Layer API directly: searching
list_metrics for "country" or "region" returns zero metrics, because
those are dimensions. That is what stranded a real client session — it
searched metrics for a dimension concept, got an empty array with no
explanation, and abandoned the tool.

Also corrects a name this guidance had wrong: the organization HQ
dimension is entity-prefixed (activity_project_id__organization_lf_region),
not a bare organization_lf_region, so the previous wording would have
produced an invalid dimension.

Spell out what metrics and dimensions each are, and that list_metrics
searches metric names and descriptions only.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Josep Garcia-Reyero Sais <josepreyero@gmail.com>
Copilot AI review requested due to automatic review settings July 28, 2026 17:12
@josep-reyero josep-reyero added the ai-assisted A task or activity that was supported by AI, such as CoPilot, ChatGPT, or other AI technology. label Jul 28, 2026

@claude claude 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.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

Copilot AI 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.

Pull request overview

Clarifies Semantic Layer metric/dimension discovery and corrects regional dimension guidance.

Changes:

  • Explains that metric search excludes dimension names.
  • Corrects the organization-region qualified-name example.
  • Updates description assertions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/tools/lens.go Improves discovery guidance and regional dimension naming.
internal/tools/lens_test.go Updates description-content assertions.

The description was 3,662 characters. Descriptions are cut at 2,048 before
the model sees them, so 44% of it was invisible — including the entity-prefix
rule, the country/region routing tip and the tlf membership caveat. The
visible half told the model memberships were an exception without ever saying
what to do instead, which is why regional questions kept landing on
query_lfx_lens.

Rewriting it meant first establishing what the tool actually offers. Probing
the live Semantic Layer showed the old framing understated it badly: it is not
"pre-aggregated metrics" (MetricFlow compiles SQL per request), and it does not
only return numbers — grouping by a name dimension returns a ranked list of
named organizations or people, which is exactly the shape of the stakeholder
question this work exists to answer.

So the description now names the six domains it covers, states that
country/region questions always belong here, and describes ranking, trending,
multi-dimension breakdown and cross-domain combination. Syntax moved onto the
parameter it governs — where carries the MetricFlow forms, group_by the
entity__field rule and grain suffixes — because each jsonschema description is
a separate field with its own budget, and the model reads it at the moment it
fills that field. That redistribution is what made room; the description had
been rationing characters against a limit the parameters do not share.

describe is renamed help, since it is now a fallback for a failed query rather
than a prerequisite. The old name still dispatches so a cached schema does not
break.

Verified end to end against the live stack rather than by compiling SQL alone:
both motivating questions return real data, and the ranked-list example was
wrong — it filtered lf_region on 'Asia', which compiles but matches nothing.
The value is 'Asia Pacific'. compileSql validates dimension names, never
values. The example is fixed and the region values are enumerated.

Tests now guard the budget in bytes rather than characters: em-dashes cost
three bytes each and the description ran ~30 bytes over its character count.
Coverage extends to every parameter and to query_lfx_lens, which has far less
headroom and is the likelier of the two to drift past the cut unnoticed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Josep Garcia-Reyero Sais <josepreyero@gmail.com>
@josep-reyero

Copy link
Copy Markdown
Contributor Author

Superseded by #109. Same commits, branch renamed to fix/semantic-layer-tool-description — the scope grew well past "correct regional dimension names" into a full rewrite of the tool description and its parameter schemas. GitHub's branch-rename API is blocked by org rulesets here, so this had to move to a new PR rather than retarget in place.

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

internal/tools/lens.go:175

  • This now advertises sponsorship metrics in the semantic layer, but query_lfx_lens still says to always route event sponsorships there because the semantic layer only handles non-sponsorship event data (internal/tools/lens.go:50). These conflicting tool descriptions can send clients to the wrong backend. Remove sponsorship here unless support/routing has changed, in which case the other tool description must be updated in this PR too.
- events — event, registration, speaker, sponsorship counts and revenue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted A task or activity that was supported by AI, such as CoPilot, ChatGPT, or other AI technology.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants