{"record":{"id":"c2f149474cc9561b","repo":"ZhuLinsen/daily_stock_analysis","slug":"hermes-base-url-must-not-include-params-query-or","errorCode":null,"errorMessage":"Hermes BASE_URL must not include params, query, or fragment","messagePattern":"Hermes BASE_URL must not include params, query, or fragment","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llm/hermes.py","lineNumber":175,"sourceCode":"\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\n    try:\n        port = parsed.port\n    except ValueError as exc:\n        raise ValueError(\"Hermes BASE_URL contains an invalid port\") from exc","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/llm/hermes.py#L157-L193","documentation":"Purity check in canonicalize_hermes_base_url: parsed.params, parsed.query, or parsed.fragment must all be empty. The Hermes endpoint is fixed at the /v1 root; query strings (?key=...), fragments (#section), and params (;a=b) are not part of the contract and typically indicate a pasted documentation URL or an attempt to smuggle options/keys via the URL.","triggerScenarios":"BASE_URL like 'http://127.0.0.1:8642/v1?token=abc', 'http://127.0.0.1:8642/v1#chat', or copied from API docs that include example query parameters.","commonSituations":"Pasting a URL straight from provider docs (which often include ?api-version=... style params); attempting per-request configuration through the base URL.","solutions":["Strip everything after the path: use exactly 'http://127.0.0.1:8642/v1'.","Move any intended options into the proper config fields, not the URL."],"exampleFix":"# before\nBASE_URL=http://127.0.0.1:8642/v1?api_key=abc\n\n# after\nBASE_URL=http://127.0.0.1:8642/v1","handlingStrategy":"validation","validationCode":"parsed = urlparse(base_url)\nassert not (parsed.params or parsed.query or parsed.fragment), \"strip query/fragment from BASE_URL\"","typeGuard":"def url_is_bare(value: str) -> bool:\n    p = urlparse(value)\n    return not (p.params or p.query or p.fragment)","tryCatchPattern":"try:\n    url = canonicalize_hermes_base_url(cfg.base_url)\nexcept ValueError as exc:\n    raise ConfigError(str(exc)) from exc","preventionTips":["Do not paste doc-page URLs with query params into config","Configure options via dedicated fields, never via URL query strings"],"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"}