{"record":{"id":"8b2a53b308b70b3a","repo":"ruvnet/RuView","slug":"threshold-must-be-between-0-0-and-1-0","errorCode":null,"errorMessage":"Threshold must be between 0.0 and 1.0","messagePattern":"Threshold must be between 0\\.0 and 1\\.0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"archive/v1/src/config/domains.py","lineNumber":182,"sourceCode":"    # Processing settings\n    batch_size: int = Field(default=1, description=\"Batch size for inference\")\n    confidence_threshold: float = Field(default=0.5, description=\"Confidence threshold\")\n    nms_threshold: float = Field(default=0.4, description=\"NMS threshold\")\n    \n    # Output settings\n    max_detections: int = Field(default=10, description=\"Maximum detections per frame\")\n    keypoint_count: int = Field(default=17, description=\"Number of keypoints\")\n    \n    # Performance settings\n    use_gpu: bool = Field(default=True, description=\"Use GPU acceleration\")\n    gpu_memory_fraction: float = Field(default=0.5, description=\"GPU memory fraction\")\n    num_threads: int = Field(default=4, description=\"Number of CPU threads\")\n    \n    @validator(\"confidence_threshold\", \"nms_threshold\", \"gpu_memory_fraction\")\n    def validate_thresholds(cls, v):\n        \"\"\"Validate threshold values.\"\"\"\n        if not 0.0 <= v <= 1.0:\n            raise ValueError(\"Threshold must be between 0.0 and 1.0\")\n        return v\n\n\nclass StreamingConfig(BaseModel):\n    \"\"\"Configuration for real-time streaming.\"\"\"\n    \n    # Stream settings\n    fps: int = Field(default=30, description=\"Frames per second\")\n    resolution: str = Field(default=\"720p\", description=\"Stream resolution\")\n    quality: str = Field(default=\"medium\", description=\"Stream quality\")\n    \n    # Buffer settings\n    buffer_size: int = Field(default=100, description=\"Buffer size\")\n    max_latency_ms: int = Field(default=100, description=\"Maximum latency in milliseconds\")\n    \n    # Compression settings\n    compression_enabled: bool = Field(default=True, description=\"Enable compression\")\n    compression_level: int = Field(default=5, description=\"Compression level (1-9)\")","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/config/domains.py#L164-L200","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the ValidationError 'loc' to see which of the three fields is out of range","Convert percent values to fractions (85% -> 0.85, 50% -> 0.5)","Clamp noisy external input into [0.0, 1.0] before constructing the model","Document the fraction convention next to the keys in the config file"],"exampleFix":"# before\nconfig = PoseModelConfig(confidence_threshold=85, gpu_memory_fraction=150)\n\n# after\nconfig = PoseModelConfig(confidence_threshold=0.85, gpu_memory_fraction=0.5)","handlingStrategy":"validation","validationCode":"def in_unit_range(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and 0.0 <= v <= 1.0\n\nassert in_unit_range(cfg.get(\"confidence_threshold\", 0.5))\nassert in_unit_range(cfg.get(\"nms_threshold\", 0.4))\nassert in_unit_range(cfg.get(\"gpu_memory_fraction\", 0.5))","typeGuard":"def is_unit_fraction(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and 0.0 <= float(v) <= 1.0","tryCatchPattern":"from pydantic import ValidationError\ntry:\n    pose_cfg = PoseModelConfig(**model_data)\nexcept ValidationError as e:\n    unit_fields = {\"confidence_threshold\", \"nms_threshold\", \"gpu_memory_fraction\"}\n    bad = [err[\"loc\"][-1] for err in e.errors() if err[\"loc\"][-1] in unit_fields]\n    if bad:\n        raise ValueError(f\"thresholds must be fractions in [0,1], got bad fields: {bad}\") from e\n    raise","preventionTips":["Author configs with fraction conventions (0.85, not 85)","Validate external config sources with an in-range check before model construction","Add CI config linting that loads all example configs to catch out-of-range values early"],"tags":["pydantic","validation","config","pose","python"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}