{"record":{"id":"67cde11b129badd9","repo":"unslothai/unsloth","slug":"guidance-start-must-be-guidance-end","errorCode":null,"errorMessage":"guidance_start must be <= guidance_end","messagePattern":"guidance_start must be <= guidance_end","errorType":"validation","errorClass":"ValueError","httpStatus":422,"severity":"error","filePath":"studio/backend/models/inference.py","lineNumber":2924,"sourceCode":"    control_type: str = Field(\n        \"passthrough\",\n        description = \"How to derive the control map: 'passthrough' (already a map) or 'canny'\",\n    )\n    strength: float = Field(\n        1.0, ge = 0.0, le = 2.0, description = \"ControlNet conditioning scale; 0 disables\"\n    )\n    guidance_start: float = Field(\n        0.0, ge = 0.0, le = 1.0, description = \"Fraction of steps at which ControlNet begins\"\n    )\n    guidance_end: float = Field(\n        1.0, ge = 0.0, le = 1.0, description = \"Fraction of steps at which ControlNet ends\"\n    )\n\n    @model_validator(mode = \"after\")\n    def _check_guidance_range(self) -> \"ControlNetSpec\":\n        # An inverted range means \"act over no steps\"; reject it as a clean 422 instead of a 500 deep in the denoise.\n        if self.guidance_start > self.guidance_end:\n            raise ValueError(\"guidance_start must be <= guidance_end\")\n        return self\n\n\nclass DiffusionGenerateRequest(BaseModel):\n    \"\"\"Request to generate one image from the loaded diffusion model.\"\"\"\n\n    prompt: str = Field(..., min_length = 1, description = \"Text prompt\")\n    negative_prompt: Optional[str] = Field(\n        None, description = \"What to avoid (if the model supports it)\"\n    )\n    width: int = Field(1024, ge = 256, le = 2048, description = \"Image width in pixels (multiple of 16)\")\n    height: int = Field(\n        1024, ge = 256, le = 2048, description = \"Image height in pixels (multiple of 16)\"\n    )\n    steps: int = Field(9, ge = 1, le = 100, description = \"Number of denoising steps\")\n    guidance: float = Field(0.0, ge = 0.0, le = 20.0, description = \"Classifier-free guidance scale\")\n    # le = 2**53-1: seeds round-trip through JSON recipes, where JavaScript rounds larger integers and a restored recipe would differ.\n    seed: Optional[int] = Field(","sourceCodeStart":2906,"sourceCodeEnd":2942,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/models/inference.py#L2906-L2942","documentation":"Raised by a ControlNetSpec model_validator when guidance_start > guidance_end. Both are fractions in [0,1] of the denoise schedule; an inverted range would mean 'act over no steps', producing silently unguided output or a 500 deep in the denoise loop — rejected up front as a clean 422 instead.","triggerScenarios":"Sending controlnet: {\"guidance_start\": 0.8, \"guidance_end\": 0.2} with a diffusion generation request; commonly from swapping the two fields or from UI sliders that can cross.","commonSituations":"Two independent sliders for start/end where dragging one past the other is possible; configs authored with 'start when ControlNet ends' semantics reversed; copying examples from a tool that uses inverted notation.","solutions":["Swap or clamp the values so guidance_start <= guidance_end.","Enforce the ordering in the UI (when start moves past end, push end along).","If you intended 'no guidance', omit the ControlNetSpec instead of an empty range."],"exampleFix":"# before\ncontrolnet = {\"guidance_start\": 0.8, \"guidance_end\": 0.2}\n\n# after\nstart, end = sorted((0.8, 0.2))\ncontrolnet = {\"guidance_start\": start, \"guidance_end\": end}","handlingStrategy":"validation","validationCode":"def clamp_controlnet(spec: dict) -> dict:\n    start, end = spec.get('guidance_start', 0.0), spec.get('guidance_end', 1.0)\n    if start > end:\n        start, end = end, start\n    return {**spec, 'guidance_start': start, 'guidance_end': end}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Constrain UI sliders so start cannot cross end","Order the pair (min, max) at request-build time","Omit the ControlNetSpec entirely when no guidance is wanted"],"tags":["pydantic","validation","controlnet","diffusion","range"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}