{"record":{"id":"7dc12c78ca046937","repo":"ZhuLinsen/daily_stock_analysis","slug":"hermes-base-url-must-include-a-loopback-host","errorCode":null,"errorMessage":"Hermes BASE_URL must include a loopback host","messagePattern":"Hermes BASE_URL must include a loopback host","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llm/hermes.py","lineNumber":171,"sourceCode":"    normalized = (protocol or HERMES_DEFAULT_PROTOCOL).strip().lower() or HERMES_DEFAULT_PROTOCOL\n    if normalized != HERMES_DEFAULT_PROTOCOL:\n        raise ValueError(\"Hermes only supports PROTOCOL=openai\")\n    return HERMES_DEFAULT_PROTOCOL\n\n\ndef canonicalize_hermes_base_url(base_url: str) -> str:\n    \"\"\"Return canonical Hermes base URL or raise ValueError.\n\n    Allowed forms are loopback HTTP(S) URLs whose path is exactly /v1 or /v1/.\n    localhost is canonicalized to 127.0.0.1 to avoid DNS/hosts ambiguity.\n    \"\"\"\n\n    raw = (base_url or HERMES_DEFAULT_BASE_URL).strip() or HERMES_DEFAULT_BASE_URL\n    parsed = urlparse(raw)\n    if parsed.scheme.lower() not in {\"http\", \"https\"}:\n        raise ValueError(\"Hermes BASE_URL must use http or https\")\n    if not parsed.netloc or not parsed.hostname:\n        raise ValueError(\"Hermes BASE_URL must include a loopback host\")\n    if parsed.username or parsed.password:\n        raise ValueError(\"Hermes BASE_URL must not include userinfo\")\n    if parsed.params or parsed.query or parsed.fragment:\n        raise ValueError(\"Hermes BASE_URL must not include params, query, or fragment\")\n\n    raw_path = parsed.path or \"\"\n    decoded_path = unquote(raw_path)\n    if decoded_path not in {\"/v1\", \"/v1/\"}:\n        raise ValueError(\"Hermes BASE_URL path must be /v1\")\n    if quote(decoded_path, safe=\"/\") != raw_path.rstrip(\"/\") and raw_path not in {\"/v1\", \"/v1/\"}:\n        raise ValueError(\"Hermes BASE_URL path must not contain encoded segments\")\n\n    hostname = parsed.hostname.strip().lower()\n    if hostname == \"localhost\":\n        hostname = \"127.0.0.1\"\n    elif hostname not in {\"127.0.0.1\", \"::1\"}:\n        raise ValueError(\"Hermes BASE_URL must point to 127.0.0.1, localhost, or [::1]\")\n","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/llm/hermes.py#L153-L189","documentation":"Host-presence check in canonicalize_hermes_base_url: after scheme validation, the URL must have a netloc and a parseable hostname. URLs like 'http://' (empty authority), 'http:///v1' (empty netloc), or 'http://:8642/v1' (port but no host) fail here. Note the message says 'loopback host' because the immediately following checks enforce loopback — this check only verifies a host exists at all.","triggerScenarios":"BASE_URL='http://' or 'http:///v1'; a URL where the host got dropped by templating/env substitution leaving an empty value mid-URL.","commonSituations":"Env var interpolation producing 'http://${HOST}:8642/v1' with HOST unset in some shells; truncated copy-paste of the URL.","solutions":["Set a complete URL with an explicit loopback host: http://127.0.0.1:8642/v1 (localhost and [::1] are also accepted and canonicalized).","Check for unset/empty variables used inside BASE_URL templates."],"exampleFix":"# before\nBASE_URL=http:///v1\n\n# after\nBASE_URL=http://127.0.0.1:8642/v1","handlingStrategy":"validation","validationCode":"parsed = urlparse(base_url)\nassert parsed.netloc and parsed.hostname, \"BASE_URL needs a host\"","typeGuard":"def url_has_host(value: str) -> bool:\n    p = urlparse(value)\n    return bool(p.netloc and p.hostname)","tryCatchPattern":"try:\n    url = canonicalize_hermes_base_url(cfg.base_url)\nexcept ValueError as exc:\n    raise ConfigError(str(exc)) from exc","preventionTips":["Use the complete literal URL http://127.0.0.1:8642/v1","Check env interpolation for empty variables inside URLs","Never truncate URLs when copying"],"tags":["hermes","llm","config","url-validation"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}