{"record":{"id":"03624e20f653c147","repo":"datawhalechina/hello-agents","slug":"llm-temperature-0-2","errorCode":null,"errorMessage":"LLM_TEMPERATURE 必须位于 0 到 2 之间","messagePattern":"LLM_TEMPERATURE 必须位于 0 到 2 之间","errorType":"exception","errorClass":"ConfigurationError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/zenith191-RequirementClarifierAgent/src/config.py","lineNumber":78,"sourceCode":"        missing = [\n            name\n            for name, value in (\n                (\"LLM_MODEL_ID\", self.model),\n                (\"LLM_API_KEY\", self.api_key),\n                (\"LLM_BASE_URL\", self.base_url),\n            )\n            if not value\n        ]\n        if missing:\n            raise ConfigurationError(\n                \"缺少 LLM 配置：\" + \", \".join(missing) + \"。请先复制并填写 .env。\"\n            )\n\n        lowered_key = self.api_key.casefold()\n        if lowered_key.startswith(\"your_\") or lowered_key in {\"changeme\", \"replace_me\"}:\n            raise ConfigurationError(\"LLM_API_KEY 仍是占位符，请在 .env 中填写真实密钥\")\n        if not 0 <= self.temperature <= 2:\n            raise ConfigurationError(\"LLM_TEMPERATURE 必须位于 0 到 2 之间\")\n        if self.timeout <= 0:\n            raise ConfigurationError(\"LLM_TIMEOUT 必须大于 0\")\n","sourceCodeStart":60,"sourceCodeEnd":81,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/zenith191-RequirementClarifierAgent/src/config.py#L60-L81","documentation":"Raised by LLMSettings validation when LLM_TEMPERATURE (or the temperature field) is outside [0, 2]. The bounds match the OpenAI-style temperature range; values like -0.1 or 2.5 are rejected before the LLM client is created, avoiding a provider-side 400 later.","triggerScenarios":"Setting LLM_TEMPERATURE=-1 for 'more deterministic' output, or 3.0 expecting 'more creative', or a typo like 22 instead of 2.2. Also a non-default temperature passed programmatically to LLMSettings(...).","commonSituations":"Migrating configs between providers whose temperature ranges differ (some allow 0–1 only, others 0–2); hand-editing .env and dropping the decimal point; experimenting with sampling values from another model's docs.","solutions":["Set LLM_TEMPERATURE to a value between 0 and 2 inclusive (e.g. 0.2).","Unset the variable to fall back to the default of 0.2 if you don't need to tune it.","If you truly need provider-specific ranges, clamp in your own wrapper before building settings."],"exampleFix":"# .env before\nLLM_TEMPERATURE=2.5\n\n# .env after\nLLM_TEMPERATURE=1.5","handlingStrategy":"validation","validationCode":"import os\n\nraw = os.getenv(\"LLM_TEMPERATURE\", \"0.2\")\ntemp = float(raw)\nassert 0 <= temp <= 2, f\"LLM_TEMPERATURE={temp} outside [0, 2]\"","typeGuard":null,"tryCatchPattern":"try:\n    settings = LLMSettings.from_env()\nexcept ConfigurationError as e:\n    if \"TEMPERATURE\" in str(e):\n        os.environ[\"LLM_TEMPERATURE\"] = \"0.2\"  # reset to default and retry\n        settings = LLMSettings.from_env()\n    else:\n        raise","preventionTips":["Document valid ranges inline in .env.example comments.","Clamp user-provided sampling params at the API boundary before they reach config.","Prefer unset-and-default over hand-typed values until tuning is deliberate."],"tags":["python","configuration","validation","llm"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}