Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:416rehman DeepZero Sort

From Leeroopedia
Knowledge Sources
Domains Ranking, Reduce
Last Updated 2026-10-27 00:00 GMT

Overview

Built-in ReduceProcessor that reorders all active samples by an upstream data field, preserving every sample and changing only the processing order for downstream stages.

Description

The Sort class is a built-in ReduceProcessor (registered as sort) that ranks samples by a metric from an upstream stage without dropping any. It uses a typed Config dataclass with two fields:

  • by: a string in stage_name.data_key format (e.g., "semgrep_scanner.finding_count") specifying which upstream field to sort on.
  • order: "desc" (default, highest-first) or "asc" (lowest-first).

The validate method ensures by is non-empty and correctly formatted. The process method reads the field from each sample's history (via entry.history[stage_name].data[data_key]), coerces it to float (missing or non-numeric values default to 0.0), and sorts. It returns all sample IDs in the new order — no samples are filtered out.

This is the K=0 variant of TopK ranking: the corpus is ordered for downstream benefit (e.g., processing the most promising samples first) without discarding any work.

Usage

  • Prioritize by finding count: by: "semgrep_scanner.finding_count", order: "desc".
  • Order by priority score: by: "discover.priority_score", order: "desc".
  • Ascending order (least-likely first): order: "asc".

Code Reference

Source Location

Signature

class Sort(ReduceProcessor):
    description = "sorts active samples by an upstream data field - preserves all samples, changes processing order"

    @dataclass
    class Config:
        by: str = ""
        order: str = "desc"

    def validate(self, ctx: ProcessorContext) -> list[str]: ...

    def process(self, ctx: ProcessorContext, samples: list[ProcessorEntry]) -> list[str]: ...

Import

from deepzero.stages.sort import Sort

I/O Contract

Inputs

Name Type Required Description
by str Yes (config) "stage_name.data_key" path to the sort field
order str No (config) "desc" (default) or "asc"
samples list[ProcessorEntry] Yes (runtime) All active samples

Outputs

Name Type Description
returns list[str] All sample IDs in sorted order (no samples dropped)

Usage Examples

Sort by Finding Count (Descending)

stages:
  - name: semgrep_scanner
    processor: semgrep_scanner
    config:
      rules: "./rules/"
  - name: rank_by_findings
    processor: sort
    config:
      by: "semgrep_scanner.finding_count"
      order: "desc"
  # Downstream stages now process highest-finding samples first
  - name: llm_assess
    processor: generic_llm
    config:
      prompt: "Assess this driver for vulnerabilities..."

Sort by Priority Score (Ascending)

# Process least-likely samples first
stages:
  - name: discover
    processor: file_discovery
    config:
      extensions: ["sys"]
  - name: ascending_priority
    processor: sort
    config:
      by: "discover.priority_score"
      order: "asc"

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment