Skip to content

AI context: a metric concept carries its filters, granularity and unit - #37419

Merged
tomasmontielp merged 3 commits into
mainfrom
ai-sql-qa-fixes
Nov 11, 2026
Merged

tomasmontielp merged 3 commits into
mainfrom
ai-sql-qa-fixes

Conversation

@tomasmontielp

@tomasmontielp tomasmontielp commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #37476
Related: open-metadata/openmetadata-collate#8310

Replaces #37193 (closed when its branch was renamed to ai-sql-qa-fixes; its reviews are there).

Describe your changes:

A metric's concept context (GET /metrics/name/{fqn}/context) carried only its expression and bindings, so the agent computing it never saw the rest of what defines the number:

  • filters: the SQL conditions the metric is defined under (status = 'paid'). Without them the agent computes the metric unfiltered, and the number is wrong.
  • granularity: the time grain it is reported at.
  • unit: the unit it is measured in; the custom unit when unitOfMeasurement is OTHER. QA found a DOLLARS metric whose $ in the answer was only the model's guess.

conceptContext gains the three optional fields; ConceptContextBuilder fills them for a metric (each omitted when the metric does not declare it), and ConceptContextMarkdown renders them under the definition. The filters all apply, so they render as one conjunction, (a)\nAND (b), and never as a list a model could read as alternatives. Blank conditions are dropped. Type, dimensions, measures and the variant hierarchy stay out: they do not change the number.

Decision record: ADR:2026-11-10-a-metric-concept-context-carries-what-changes-its-number (the conceptContext metric fields are a contract ai-platform reads).

Companion: open-metadata/ai-platform renders the same fields in the SQL and worker concept text (open-metadata/ai-platform#2155, which also carries the former ai-platform#2061); it builds against this one, so this merges first.

Type of change:

  • Improvement

Verification

  • New tests: ConceptContextBuilderTest.metricCarriesWhatDefinesItsNumber, metricNamesItsCustomUnitAndOmitsWhatItDoesNotDeclare; ConceptContextMarkdownTest.rendersWhatDefinesAMetricsNumber (now also asserts two filters render as (a)\nAND (b)).
  • Run locally at fe76f007efc (isolated Maven repo): mvn -pl openmetadata-service test -Dtest='ConceptContextMarkdownTest,ConceptContextBuilderTest': 28 run, 0 failed. The first run caught a whitespace-only filter passing through; fixed in the same commit.
  • mvn spotless:apply: clean.

Checklist:

  • I have read the CONTRIBUTING document.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests around the new logic.

@tomasmontielp tomasmontielp added the safe to test Add this label to run secure Github workflows on PRs label Nov 9, 2026
@tomasmontielp tomasmontielp self-assigned this Nov 9, 2026
@tomasmontielp
tomasmontielp marked this pull request as ready for review November 9, 2026 18:09
@tomasmontielp
tomasmontielp requested a review from a team as a code owner November 9, 2026 18:09
@tomasmontielp
tomasmontielp requested a review from TeddyCr November 9, 2026 18:09
@tomasmontielp

Copy link
Copy Markdown
Contributor Author

@claude review

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

✅ Generated Sources Auto-Updated

The generated TypeScript types (src/generated/) and dereferenced JSON
schemas (src/jsons/, public/jsons/) have been automatically updated
based on JSON schema changes in this PR.

@gitar-bot

gitar-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🟡 Medium risk · Adding metric filters, granularity, and units to AI context changes how agents compute and report values; misapplied conditions could produce incorrect answers.

Adds filters, granularity and unit to the metric concept context so the agent computes metrics with the conditions and unit that define their number. No open issues remain. Resolved: a decision record now covers the new conceptContext metric fields, and multiple filters are newline-joined with their combination made explicit.

✅ 2 closed
✅ Quality: No decision record for the new conceptContext metric fields

📄 openmetadata-spec/src/main/resources/json/schema/type/aiContext.json:503-515 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/ConceptContextBuilder.java:119-123 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/ConceptContextBuilder.java:240-254
This PR adds filters, granularity and unit to the conceptContext schema in aiContext.json. That is a payload contract that open-metadata/ai-platform#2155 builds against, and no record in docs/decisions/ covers it. The description also states rules that exist nowhere in the tree. Because the repo squash-merges, those rules will be lost:

  • "Type, dimensions, measures and the variant hierarchy stay out: they do not change the number"
  • "the custom unit when unitOfMeasurement is OTHER"

The record would say: A metric's concept context carries only what changes or reads its number. That is its expression, every where filter (all of them apply together with the definition), its granularity, and its unit: the custom unit when unitOfMeasurement is OTHER and a custom unit is given, otherwise the enum value. Type, dimensions, measures and the variant hierarchy stay out. It could also name the guard tests ConceptContextBuilderTest.metricCarriesWhatDefinesItsNumber and ConceptContextMarkdownTest.rendersWhatDefinesAMetricsNumber.

✅ Edge Case: Multiple filters are newline-joined, so how they combine is unclear

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/ConceptContextMarkdown.java:76-79
When a metric has more than one MetricFilter, ConceptContextMarkdown joins the where clauses with inside one ```sql block. For example, status = 'paid' followed by `region = 'EU' OR region = 'UK'` renders as two bare lines. That is not valid SQL, and it does not say whether the conditions are ANDed or ORed. If a model ANDs them without parentheses, the second filter's `OR` binds wrongly and the number is wrong, which is the failure this PR exists to prevent. The schema description already says each filter is "applied with the definition", so the fix is to render them as parenthesized, AND-joined conditions.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 81%
81.8% (142381/174045) 69.3% (52208/75327) 72.29% (29221/40418)

@tomasmontielp
tomasmontielp merged commit 3d1bc01 into main Nov 11, 2026
82 of 85 checks passed
@tomasmontielp
tomasmontielp deleted the ai-sql-qa-fixes branch November 11, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.1 safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI context: a metric concept omits its filters, granularity and unit

3 participants