ruvnet/RuView · error · ValueError

Threshold must be between 0.0 and 1.0

Error message

Threshold must be between 0.0 and 1.0

What it means

Pydantic v1 @validator on the pose model config in archive/v1/src/config/domains.py. It enforces 0.0 <= value <= 1.0 for three fields: confidence_threshold, nms_threshold, and gpu_memory_fraction. Raising ValueError inside a validator surfaces as pydantic.ValidationError at model construction time, listing the offending field in the error 'loc'. Values are treated as fractions, not percentages.

Source

Thrown at archive/v1/src/config/domains.py:182

    # Processing settings
    batch_size: int = Field(default=1, description="Batch size for inference")
    confidence_threshold: float = Field(default=0.5, description="Confidence threshold")
    nms_threshold: float = Field(default=0.4, description="NMS threshold")
    
    # Output settings
    max_detections: int = Field(default=10, description="Maximum detections per frame")
    keypoint_count: int = Field(default=17, description="Number of keypoints")
    
    # Performance settings
    use_gpu: bool = Field(default=True, description="Use GPU acceleration")
    gpu_memory_fraction: float = Field(default=0.5, description="GPU memory fraction")
    num_threads: int = Field(default=4, description="Number of CPU threads")
    
    @validator("confidence_threshold", "nms_threshold", "gpu_memory_fraction")
    def validate_thresholds(cls, v):
        """Validate threshold values."""
        if not 0.0 <= v <= 1.0:
            raise ValueError("Threshold must be between 0.0 and 1.0")
        return v


class StreamingConfig(BaseModel):
    """Configuration for real-time streaming."""
    
    # Stream settings
    fps: int = Field(default=30, description="Frames per second")
    resolution: str = Field(default="720p", description="Stream resolution")
    quality: str = Field(default="medium", description="Stream quality")
    
    # Buffer settings
    buffer_size: int = Field(default=100, description="Buffer size")
    max_latency_ms: int = Field(default=100, description="Maximum latency in milliseconds")
    
    # Compression settings
    compression_enabled: bool = Field(default=True, description="Enable compression")
    compression_level: int = Field(default=5, description="Compression level (1-9)")

View on GitHub (pinned to 4685618388)

Solutions

  1. Read the ValidationError 'loc' to see which of the three fields is out of range
  2. Convert percent values to fractions (85% -> 0.85, 50% -> 0.5)
  3. Clamp noisy external input into [0.0, 1.0] before constructing the model
  4. Document the fraction convention next to the keys in the config file

Example fix

# before
config = PoseModelConfig(confidence_threshold=85, gpu_memory_fraction=150)

# after
config = PoseModelConfig(confidence_threshold=0.85, gpu_memory_fraction=0.5)
Defensive patterns

Strategy: validation

Validate before calling

def in_unit_range(v) -> bool:
    return isinstance(v, (int, float)) and not isinstance(v, bool) and 0.0 <= v <= 1.0

assert in_unit_range(cfg.get("confidence_threshold", 0.5))
assert in_unit_range(cfg.get("nms_threshold", 0.4))
assert in_unit_range(cfg.get("gpu_memory_fraction", 0.5))

Type guard

def is_unit_fraction(v) -> bool:
    return isinstance(v, (int, float)) and not isinstance(v, bool) and 0.0 <= float(v) <= 1.0

Try / catch

from pydantic import ValidationError
try:
    pose_cfg = PoseModelConfig(**model_data)
except ValidationError as e:
    unit_fields = {"confidence_threshold", "nms_threshold", "gpu_memory_fraction"}
    bad = [err["loc"][-1] for err in e.errors() if err["loc"][-1] in unit_fields]
    if bad:
        raise ValueError(f"thresholds must be fractions in [0,1], got bad fields: {bad}") from e
    raise

Prevention

When it happens

Trigger: Constructing the pose config with confidence_threshold=1.2 or -0.1; setting nms_threshold outside [0,1]; gpu_memory_fraction=2 (intending 200% of GPU memory); loading a domain config file where any of these three keys holds a percentage (e.g., 85) instead of a fraction.

Common situations: Config authored with 0-100 percent conventions from another tool; a default overridden with an out-of-range value during perf tuning; YAML floats parsed as strings still failing after coercion because the numeric value is out of range.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/8b2a53b308b70b3a. Report an issue: GitHub.