nexu-io/open-design · error · ValueError

SubQuery must have at least one source

Error message

SubQuery must have at least one source

What it means

SubQuery is a frozen dataclass representing one planner-emitted retrieval unit. Its __post_init__ enforces that sources is non-empty, because a retrieval unit with no source has nowhere to dispatch and would fall straight through stream_results to 'Unsupported source'. The guard fails the construction early instead of at retrieval time.

Source

Thrown at design-templates/last30days/scripts/lib/schema.py:53

    reasoning_provider: Literal["gemini", "openai", "xai", "local"]
    planner_model: str
    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

View on GitHub (pinned to 5be4028344)

Solutions

  1. Ensure the planner always emits at least one supported source per subquery.
  2. When filtering subquery sources, drop the whole subquery if the filter empties its sources list.
  3. Validate the planner JSON shape (sources is a non-empty list of known names) before constructing SubQuery objects.

Example fix

# before
SubQuery(label='t', search_query='q', ranking_query='q', sources=[])

# after
SubQuery(label='t', search_query='q', ranking_query='q', sources=['reddit', 'hackernews'])
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")
    return SubQuery(label, search_query, ranking_query, list(sources), weight=weight)

Type guard

def has_sources(sources) -> bool:
    return isinstance(sources, (list, tuple)) and len(sources) > 0

Try / catch

null

Prevention

When it happens

Trigger: Constructing SubQuery(..., sources=[]) or sources=None. Typically the planner LLM emitted a subquery whose sources list was stripped/emptied by post-processing, or a hand-built plan forgot the field.

Common situations: Planner JSON parse that filtered out all unsupported sources and left an empty list. Refactor that builds SubQuery from a dict missing the 'sources' key. Test fixtures that defaulted sources to [].

Related errors


AI-assisted analysis of nexu-io/open-design@5be4028344 (2026-08-12). Data as JSON: /api/errors/fef84a3b9b03620e. Report an issue: GitHub.