SigNoz/signoz · error
unknown variable %s
Error message
unknown variable %s
What it means
Every variable referenced in a builder expression must correspond to another builder query's Expression (its name). If a variable like C is used but no builder query defines it, this error is returned from validateExpressions during query-range validation.
Source
Thrown at pkg/query-service/app/parser.go:725
// allowed functions.
func validateExpressions(expressions []string, funcs map[string]govaluate.ExpressionFunction, cq *v3.CompositeQuery) []error {
var errs []error
for _, exp := range expressions {
evalExp, err := govaluate.NewEvaluableExpressionWithFunctions(exp, funcs)
if err != nil {
errs = append(errs, fmt.Errorf("invalid expression %s: %v", exp, err))
continue
}
for _, v := range evalExp.Vars() {
var hasVariable bool
for _, q := range cq.BuilderQueries {
if q.Expression == v {
hasVariable = true
break
}
}
if !hasVariable {
errs = append(errs, fmt.Errorf("unknown variable %s", v))
}
}
}
return errs
}
// chTransformQuery transforms the clickhouse query with the given variables
// it is used to check what would be the query if variables are selected as __all__.
// for now, this is just a pass through, but in the future, we will use it to
// dashboard variables
// TODO(srikanthccv): version based query replacement
func chTransformQuery(query string, variables map[string]interface{}) {
varsForTransform := make([]chVariables.VariableValue, 0, len(variables))
for name := range variables {
varsForTransform = append(varsForTransform, chVariables.VariableValue{
Name: name,
Values: []string{"__all__"},
IsSelectAll: true,View on GitHub (pinned to 5069bf80b0)
Solutions
- Add a builder query whose name matches the variable, or fix the variable name in the expression
- Ensure referenced queries are included in the same composite query payload
- When deleting a query, first remove expressions that reference it
Example fix
// before
{"expression": "A + C", "queries": [A, B]}
// after
{"expression": "A + B", "queries": [A, B]} Defensive patterns
Strategy: validation
Validate before calling
defined := map[string]bool{}
for name, q := range cq.BuilderQueries { defined[q.Expression] = true; defined[name] = true }
for _, v := range evalExp.Vars() { if !defined[v] { return fmt.Errorf("unknown variable %s", v) } } Type guard
func allVarsDefined(expr string, cq *v3.CompositeQuery) bool { /* compile with govaluate, check Vars() ⊆ builderQueries keys */ return true } Prevention
- When renaming/deleting queries, scan all expressions for stale references
- Build composite queries via a helper that checks variable closure
When it happens
Trigger: Expression 'A + C' where only queries A and B exist; renaming/deleting a query that is still referenced by a formula.
Common situations: Editing a dashboard panel and removing a query without updating dependent formulas; typos in variable names; API-built composite queries missing a referenced query block.
Related errors
AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28).
Data as JSON: /api/errors/8c0e00277f7bf4ab.
Report an issue: GitHub.