Calling the compare_periods MCP tool on a model with a named time dimension fails at execution time with a ColumnNotFoundError of the form:
Column 'lineitems_movements.created_at' is not found in table.
Existing columns: 'created_at', 'metric_ventas_netas_con_iva_current', ...
The comparison queries run successfully and produce result tables with the unqualified column name created_at, but somewhere in the tool execution the model-prefixed form lineitems_movements.created_at is used to reference a column in the joined result table that only exposes the unqualified name.
Steps to reproduce
Define a SemanticModel named lineitems_movements with a created_at time dimension.
Register it as an MCP server.
Call the compare_periods tool with model_name="lineitems_movements" and any pair of current_time_range / previous_time_range values, including created_at in dimensions or letting it be auto-detected as the time dimension.
Root cause (suspected)
In query.py, compare_periods correctly strips model-name prefixes from dimensions and measures via _normalize_fields (lines 626–627). However, the order_by parameter is not normalized before being applied to result_tbl (lines 702–708):
if order_by:
result_tbl = result_tbl.order_by(
[
result_tbl[field].desc() if direction.lower() == "desc" else result_tbl[field]
for field, direction in order_by
]
)
If the LLM (or caller) passes order_by=[["lineitems_movements.created_at", "desc"]], result_tbl["lineitems_movements.created_at"] fails because the column in the joined result is "created_at" (unprefixed). The query() function avoids this by calling _normalize_order_by before building order keys (line 809), but compare_periods does not.
Additionally, dimensions in the join/select block (lines 673–683) uses the values returned by _normalize_fields, which should already be unprefixed — worth double-checking that the normalization is applied consistently before those column lookups.
Suggested fix
Apply _normalize_order_by (already available in query.py) to the order_by argument against the result table columns before building the order expressions:
if order_by:
result_columns = set(result_tbl.columns)
order_by = _normalize_order_by(order_by, result_columns)
result_tbl = result_tbl.order_by(
[
result_tbl[field].desc() if direction.lower() == "desc" else result_tbl[field]
for field, direction in order_by
]
)

Calling the compare_periods MCP tool on a model with a named time dimension fails at execution time with a ColumnNotFoundError of the form:
Column 'lineitems_movements.created_at' is not found in table.
Existing columns: 'created_at', 'metric_ventas_netas_con_iva_current', ...
The comparison queries run successfully and produce result tables with the unqualified column name created_at, but somewhere in the tool execution the model-prefixed form lineitems_movements.created_at is used to reference a column in the joined result table that only exposes the unqualified name.
Steps to reproduce
Define a SemanticModel named lineitems_movements with a created_at time dimension.
Register it as an MCP server.
Call the compare_periods tool with model_name="lineitems_movements" and any pair of current_time_range / previous_time_range values, including created_at in dimensions or letting it be auto-detected as the time dimension.
Root cause (suspected)
In query.py, compare_periods correctly strips model-name prefixes from dimensions and measures via _normalize_fields (lines 626–627). However, the order_by parameter is not normalized before being applied to result_tbl (lines 702–708):
if order_by:
result_tbl = result_tbl.order_by(
[
result_tbl[field].desc() if direction.lower() == "desc" else result_tbl[field]
for field, direction in order_by
]
)
If the LLM (or caller) passes order_by=[["lineitems_movements.created_at", "desc"]], result_tbl["lineitems_movements.created_at"] fails because the column in the joined result is "created_at" (unprefixed). The query() function avoids this by calling _normalize_order_by before building order keys (line 809), but compare_periods does not.
Additionally, dimensions in the join/select block (lines 673–683) uses the values returned by _normalize_fields, which should already be unprefixed — worth double-checking that the normalization is applied consistently before those column lookups.
Suggested fix
Apply _normalize_order_by (already available in query.py) to the order_by argument against the result table columns before building the order expressions:
if order_by:
result_columns = set(result_tbl.columns)
order_by = _normalize_order_by(order_by, result_columns)
result_tbl = result_tbl.order_by(
[
result_tbl[field].desc() if direction.lower() == "desc" else result_tbl[field]
for field, direction in order_by
]
)