arth-semlayer
Provides a governed semantic layer over a local DuckDB warehouse: seeds DuckDB with demo data and query logs, evaluates certified metrics, and serves metric queries to agents while enforcing certification and policy.
Integrates with Google Cloud, primarily BigQuery: evaluates certified metrics against BigQuery, can use Google's managed BigQuery MCP server, ingests BigQuery job history and Dataplex policy tags, and uses Gemini for drafting descriptions.
ARTH: Semantic Layer
Repository: arth-semlayer · Python package and command: semlayer
Governed semantic layer between AI agents and your data. Definitions are drafted automatically from your schema and query log, humans certify them, and agents can only use certified ones.
GCP-integrated + local fallback: Gemini API default LLM (
ollama/openaisecondary local options), DuckDB local default warehouse + Google's managed BigQuery MCP server (https://bigquery.googleapis.com/mcp)Loop: ingest → draft → find conflicts → certify → serve over MCP → monitor drift
Agents never touch the warehouse. They call
semlayer's MCP server; certification and policy are enforced there.
Quickstart (local DuckDB)
uv sync
uv run semlayer demo # seeds DuckDB + query log, runs the loop, auto-certifies (DEMO ONLY)
uv run semlayer eval --oracle # 33-question eval of the certified layer (no LLM key needed)
uv run semlayer serve --web # review UI + JSON API on :8000
uv run semlayer serve # MCP server (stdio) for agents
uv run pytest # unit + fake-server suite (runs offline with no keys)Run every command from the project root. Local prerequisites: uv (DuckDB and SQLite are bundled).
Related MCP server: Semantic BI MCP
LLM configuration (Gemini default, local models secondary)
semlayer uses an LLM for two things only: wording metric descriptions/explanations during draft, and running the LLM eval arms. It never changes metric SQL logic.
1. Default: Gemini API via AI Studio (gemini-3.5-flash-lite)
Put your AI Studio GEMINI_API_KEY in .env (git-ignored) or your environment. semlayer.yaml defaults to:
llm_provider: gemini # gemini | ollama | openai | none
llm_model: gemini-3.5-flash-lite
llm_max_tokens: 512
llm_reasoning_effort: lowGEMINI_API_KEY authenticates directly against https://generativelanguage.googleapis.com/v1beta/openai and works alongside GCP Application Default Credentials used by BigQueryMCP.
2. Secondary option: Local models (ollama or openai)
Switch to local inference with config changes only in semlayer.yaml:
llm_provider: ollama # or "openai" for llama.cpp (:8080/v1), LM Studio (:1234/v1), vLLM
llm_model: qwen3.5:9b
# llm_url: http://localhost:11434Override without editing files via SEMLAYER_LLM_PROVIDER, SEMLAYER_LLM_MODEL, SEMLAYER_LLM_URL, or disable the LLM with --no-llm / SEMLAYER_LLM_PROVIDER=none. Without a key or running local server, draft and demo warn once and fall back to heuristic descriptions; LLM eval fails fast or aborts cleanly on quota errors (ADR-029).
GCP & BigQuery over MCP
Install the optional GCP auth dependency and sign into your GCP project:
uv sync --extra gcp
gcloud auth login --update-adc
gcloud config set project YOUR_PROJECT_ID
gcloud auth application-default set-quota-project YOUR_PROJECT_ID
gcloud services enable bigquery.googleapis.com iamcredentials.googleapis.com --project=YOUR_PROJECT_ID
gcloud beta services mcp enable bigquery.googleapis.com --project=YOUR_PROJECT_IDSeed the jaffle_shop tables into BigQuery and verify over MCP:
uv run python scripts/bq_seed.py --project YOUR_PROJECT_ID --dataset jaffle_shop
SEMLAYER_WAREHOUSE=bigquery SEMLAYER_BQ_PROJECT=YOUR_PROJECT_ID uv run semlayer eval --oracle
SEMLAYER_BQ_PROJECT=YOUR_PROJECT_ID uv run python scripts/mcp_check.py --warehouse bigqueryOr set warehouse: bigquery (and optional bq_service_account for read-only service-account impersonation) in semlayer.yaml.
Cloud-Native GCP Operations (Zero Extra Dependencies)
Ingest BigQuery Job History & Dataplex Policy Tags: Pull historical
SELECTqueries fromINFORMATION_SCHEMA.JOBS_BY_PROJECTand auto-draftdeny_dimsrules from Dataplex policy tags (INFORMATION_SCHEMA.COLUMN_FIELD_PATHS):SEMLAYER_WAREHOUSE=bigquery SEMLAYER_BQ_PROJECT=YOUR_PROJECT_ID uv run semlayer ingest --from-bq-jobs --bq-days 30 uv run semlayer draft --roles finance,eu_analystBigQuery Materialized View Advisor: Generate ready-to-review BigQuery MV DDL for high-demand certified metrics:
uv run semlayer feedback --recommend-mv --project YOUR_PROJECT_ID --dataset jaffle_shopCloud Run + Secret Manager + Scheduled Canary + Cloud Logging JSON: Pass
--log-json(SEMLAYER_LOG_JSON=1) for structured Cloud Logging output and deploy withdeploy/cloudrun/.
Real workflow (humans in the loop)
uv run python examples/jaffle_shop/seed.py
uv run semlayer ingest
uv run semlayer draft --roles finance,analyst
uv run semlayer review # ranked queue (by demand)
uv run semlayer conflicts # variants / duplicates with ranked options
uv run semlayer conflicts --split active_customers --names a_v1=active_30d a_v2=active_paid
uv run semlayer certify revenue --accept-suggested
uv run semlayer rule-add finance_all --role finance
uv run semlayer rule-add eu_customers --role eu_analyst --metric customer_count --row-filter "region = 'EU'"
uv run semlayer certify finance_all --kind rule --owner security
uv run semlayer edit revenue entity=Customer entity_key=customer_id time_dimension=paid_at synonyms=sales,turnover
uv run semlayer metric-add aov --type ratio --numerator revenue --denominator order_count --dimensions method
uv run semlayer certify aov --owner alice
uv run semlayer canary # probes certified metrics (LIMIT 0); suspends broken ones
uv run semlayer serve --role finance # strict role-bound MCP server (rejects caller as_role)
uv run semlayer drift --values
uv run semlayer feedbackIntegrations & Examples
Interactive Colab / Vertex AI Notebook:
notebooks/certified_bigquery_mcp.ipynb(Open in Colab) — self-contained walkthrough connecting Gemini (google-genaion Vertex AI) to the governed MCP server over BigQuery MCP with an offline DuckDB toggle.Google ADK Agent (
McpToolset+ FastAPI / Cloud Run):examples/adk_agent/— standalone deployable ADKLlmAgentwired to the governed stdio MCP server with Dockerfile and 27 offline tests (cd examples/adk_agent && uv sync --dev && uv run pytest).
Layout
src/semlayer/ core warehouse ingest lineage draft conflicts registry compiler graph policy monitor serve cli evaluate demo
examples/jaffle_shop/ seed.py (data + query log with deliberate conflicts)
examples/adk_agent/ Google ADK LlmAgent + governed MCP server + Dockerfile
notebooks/ certified_bigquery_mcp.ipynb (Vertex AI / Colab walkthrough)
eval/ questions.yaml, heldout.yaml (+ generators)
definitions/ the registry (YAML, Git-friendly)
scripts/ manual_run.sh, mcp_check.py, bq_seed.py
skills/semlayer/ SKILL.md for agents
tests/Docs
PLAN.md · ARCHITECTURE.md · ADR.md · EVAL.md · SECURITY.md · GEMINI.md
Available Tools
9 toolsdescribe_graphB
List entities, their filterable columns and relationship names/cardinalities.
Inputs: no named parameters.
describe_metricB
Definition, owner, version, time/joinable dimensions and lineage of one certified metric.
Inputs: name (required).
list_metricsB
List certified metrics, their dimensions and versions (supports optional limit/offset).
Inputs: limit, offset. Returns: result
query_metricC
Compute a certified metric (simple, ratio or derived). Cite name and version in answers. Omit as_role when server is started with a bound --role.
Inputs: metric (required), dims, limit, as_role, +5 more.
query_metricsC
Compute several certified metrics at the same grain without fan-out multiplication.
Inputs: metrics (required), dims, limit, as_role, +5 more.
report_gapA
Call when no certified metric can answer. question = the user's question verbatim; put any explanation in reason.
Inputs: question (required), reason, as_role.
report_issueC
Report a suspected wrong or confusing result.
Inputs: note (required), metric (required), as_role.
search_metricsB
Search certified metrics by keyword, dimension or synonym (BM25 over FTS5).
Inputs: query (required), k. Returns: result
traverse_graphB
Entity keys reachable from start along relationship names (see describe_graph).
filters example: {"Order": {"status": "returned"}}. Pass the keys as entity_keys to query_metric.
Inputs: path (required), start (required), as_role, filters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Most tools have clearly distinct purposes: discovery (list/search/describe), computation (query_metric/query_metrics), graph traversal, and feedback reporting. The only pair that could be confused is query_metric vs query_metrics, and the singular/plural boundary is explained by grain/fan-out semantics. describe_metric vs list_metrics vs search_metrics are reasonably differentiated by detail level and lookup mode.
All nine tools follow a consistent verb_noun snake_case pattern: describe_*, list_*, query_*, report_*, search_*, traverse_*. Verb choices are predictable and semantically aligned with each tool's action.
Nine tools is well within the appropriate range and each earns its place: discovery, schema description, single/batch querying, graph traversal, and two distinct feedback channels. There is no obvious redundancy or missing breadth for a semantic-layer consumer server.
The surface covers the core lifecycle well: discover metrics (list/search/describe), compute them (single and multi), understand and traverse the entity graph, and report gaps or bad results. Minor gaps exist around authoring/updating metric definitions and perhaps bulk description, but these may be intentionally out of scope for a read-only consumer server.
Maintenance
Related MCP Connectors
Query your warehouse or a CSV with Claude/ChatGPT over MCP, governed by table-level ACL + audit.
Zero-trust SQL AST & MCP firewall enforcing tenant isolation, PII scrubbing, and schema allowlists.
The grounded data layer for any LLM: governed SQL, metrics, lineage and catalog over your data.
Hosted BigQuery MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
AlicenseNot gradedqualityFmaintenanceOpen-source agentic schema layer. Define metrics once in YAML, query governed data from any warehouse (Snowflake, BigQuery, Databricks, PostgreSQL, DuckDB) via MCP.28Apache 2.0- FlicenseNot gradedqualityCmaintenanceModel Context Protocol (MCP) server that gives AI assistants a safe, correct data-analyst capability over business metrics - without raw SQL improvisation.-
- AlicenseAqualityDmaintenanceA read-only DuckDB MCP server offering context-efficient analytics tools (list_datasets, describe_table, profile_column, explain, query) with a semantic layer for business rules, security guards, and disclosed truncation to help LLMs produce correct answers while minimizing token usage.5MIT
- AlicenseDqualityDmaintenanceA local-first MCP server that provides safe, governed read-only SQL access to SQLite and PostgreSQL, with validation, limits, task tracking, and report generation.20MIT