nexu-io/open-design · error · ValueError
SubQuery weight must be positive, got {self.weight}
Error message
SubQuery weight must be positive, got {self.weight} What it means
Second invariant in SubQuery.__post_init__: weight must be > 0. Weight is used downstream for RRF-style fusion and ranking; a zero or negative weight would silently drop or invert the subquery's contribution, so construction fails loudly instead.
Source
Thrown at design-templates/last30days/scripts/lib/schema.py:55
rerank_model: str
x_search_backend: Literal["xai", "bird"] | None = None
@dataclass(frozen=True)
class SubQuery:
"""Planner-emitted retrieval unit."""
label: str
search_query: str
ranking_query: str
sources: list[str]
weight: float = 1.0
def __post_init__(self) -> None:
if not self.sources:
raise ValueError("SubQuery must have at least one source")
if self.weight <= 0:
raise ValueError(f"SubQuery weight must be positive, got {self.weight}")
@dataclass
class QueryPlan:
"""Planner output."""
intent: str
freshness_mode: str
cluster_mode: str
raw_topic: str
subqueries: list[SubQuery]
source_weights: dict[str, float]
notes: list[str] = field(default_factory=list)
@dataclass
class SourceItem:
"""Generic normalized evidence item."""View on GitHub (pinned to 5be4028344)
Solutions
- Ensure the planner emits strictly positive weights (e.g. >= 0.1).
- After any weight normalization, clamp each weight to a small positive floor before constructing SubQuery.
- Omit the weight argument to inherit the default 1.0.
Example fix
# before SubQuery(label='t', search_query='q', ranking_query='q', sources=['x'], weight=0.0) # after w = max(raw_weight, 0.1) SubQuery(label='t', search_query='q', ranking_query='q', sources=['x'], weight=w)
Defensive patterns
Strategy: validation
Validate before calling
def build_subquery(label, search_query, ranking_query, sources, weight=1.0):
if not sources:
raise ValueError(f"subquery {label!r} needs at least one source")
if weight <= 0:
raise ValueError(f"subquery {label!r} weight must be > 0, got {weight}")
return SubQuery(label, search_query, ranking_query, list(sources), weight=weight) Type guard
def is_positive_weight(w) -> bool:
return isinstance(w, (int, float)) and w > 0 Try / catch
null
Prevention
- Clamp normalized weights to a small positive floor (e.g. max(w, 0.1)) before constructing SubQuery.
- Validate the planner weight field is a positive number at parse time.
- Default to 1.0 when the planner omits weight.
When it happens
Trigger: Constructing SubQuery(..., weight=0) or a negative weight. Reached when the planner emits a weight of 0, when a normalization step divides by a sum that produced 0, or when a default of 0 was used instead of the dataclass default 1.0.
Common situations: Planner JSON with 'weight': 0. Weight normalization that scales all weights to 0. Test fixture setting weight=0 by accident. Float parse of '0.0' string.
Related errors
- SubQuery must have at least one source
- representative_ids must be a subset of candidate_ids
- project is required (string).
- invalid JSON in ${filePath}: ${message}
- ${filePath} must contain a JSON object
AI-assisted analysis of nexu-io/open-design@5be4028344 (2026-08-12).
Data as JSON: /api/errors/fd021b0a96b4524b.
Report an issue: GitHub.