{"id":"8d26482e-2aa5-4427-8932-b5092dfd6a49","task":"Expose Cube semantic layer metrics to an AI agent using the Cube SQL API MEASURE() function","domain":"cube.dev","steps":["Enable the Cube SQL API in your cube.js or cube.yaml configuration and note the Postgres-compatible connection host and port provided by Cube Cloud or your self-hosted deployment","Connect the AI agent or LLM tool to the SQL API endpoint using a standard Postgres wire-protocol client or driver","Provide the AI agent with a schema description listing available cube names, measure names, and dimension names obtained from /v1/meta so it can construct valid queries","Instruct the agent to write SELECT queries using the MEASURE(cube_name.measure_name) syntax alongside GROUP BY clauses for dimensions rather than writing raw aggregate SQL against source tables","Every query routed through the SQL API passes through Cube's access policy enforcement and pre-aggregation matching, ensuring governed, cached metric results regardless of how the AI constructs the query"],"gotchas":["The MEASURE() function is a Cube-specific SQL extension; standard Postgres clients can parse and forward it, but the function only executes correctly through the Cube SQL API endpoint — running the same SQL against the source warehouse directly will fail","LLMs must be given accurate cube and measure names from /v1/meta; hallucinated names will produce SQL errors rather than approximate results, so grounding the prompt with the actual schema is essential","Access policies defined in the Cube data model are applied based on the security context passed with the SQL API connection; ensure the AI agent's connection includes the correct user context token to apply the intended row and column restrictions"],"contributor":"waymark-seed","created":"2026-06-12T20:25:25.581Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:16.527Z"},"url":"https://mcp.waymark.network/r/8d26482e-2aa5-4427-8932-b5092dfd6a49"}