~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(llm): make normalize_provider strip quotes like get_llm (#7828) (#7902)
Imaduddin Bhaisaheb4c67bff76baf
diff --git a/changelog.d/7828.bugfix.md b/changelog.d/7828.bugfix.mdnew file mode 100644index 0000000000..7fcdbd28f2--- /dev/null+++ b/changelog.d/7828.bugfix.md@@ -0,0 +1 @@+Provider names are now normalised the same way everywhere: `normalize_provider` strips surrounding quotes as well as whitespace, matching what `get_llm` already did. A quoted provider such as `"openai_endpoint"` (from a request's `model_provider` or a stored `llm.provider`) is no longer treated as a different provider by the research route and the error-message rewrite, so the request's `custom_endpoint` is honoured and the "Custom endpoint URL is required" check applies.diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.pyindex 1651cc62ea..9e9cb3597f 100644--- a/src/local_deep_research/config/llm_config.py+++ b/src/local_deep_research/config/llm_config.py@@ -141,11 +141,8 @@ def get_llm(if model_name:model_name = model_name.strip().strip("\"'").strip()- # Clean provider: remove quotes and extra whitespace- if provider:- provider = provider.strip().strip("\"'").strip()-- # Normalize provider: convert to lowercase canonical form+ # Normalize provider: strip surrounding quotes/whitespace and lowercase+ # (the same canonical form the route checks use).provider = normalize_provider(provider)had_settings_snapshot = settings_snapshot is not Nonediff --git a/src/local_deep_research/llm/providers/base.py b/src/local_deep_research/llm/providers/base.pyindex e7115ecf22..85a9db0547 100644--- a/src/local_deep_research/llm/providers/base.py+++ b/src/local_deep_research/llm/providers/base.py@@ -14,9 +14,12 @@ def normalize_provider(provider):"""Normalize provider name to lowercase canonical form.All provider comparisons in route/service code should use- this function to ensure consistent casing. Surrounding whitespace is- stripped too (a hand-edited or env-supplied ``" qwen "``); a- whitespace-only value normalises to None like any other empty value.+ this function to ensure consistent casing. Surrounding whitespace and+ surrounding quote characters are stripped too (a hand-edited,+ env-supplied or settings round-tripped ``" qwen "`` / ``'"ollama"'``),+ so route checks resolve a provider exactly as ``get_llm`` does. A+ value that is empty after stripping (``""``, ``" "``, ``'""'``)+ normalises to None like any other empty value.Only ``str`` input is stripped. Any other truthy value keeps thepre-strip contract exactly: it is duck-typed through ``.lower()``, so a@@ -27,7 +30,7 @@ def normalize_provider(provider):if not provider:return Noneif isinstance(provider, str):- return provider.strip().lower() or None+ return provider.strip().strip("\"'").strip().lower() or Nonereturn provider.lower()diff --git a/src/local_deep_research/security/egress/policy.py b/src/local_deep_research/security/egress/policy.pyindex 71397f88af..cd6cb25d74 100644--- a/src/local_deep_research/security/egress/policy.py+++ b/src/local_deep_research/security/egress/policy.py@@ -612,7 +612,11 @@ def _normalize_provider_key(raw) -> str:"""Normalize a provider key the way the vector-store factory does."""if not isinstance(raw, str):return ""- return raw.strip().strip("\"'").strip().lower()+ # Lazy import: ``llm.providers.base`` imports ``security.egress``, so a+ # module-level import here would be circular.+ from ...llm.providers.base import normalize_provider++ return normalize_provider(raw) or ""def _resolve_index_vector_store_providers(diff --git a/tests/llm/test_provider_adapter_contracts.py b/tests/llm/test_provider_adapter_contracts.pyindex 015c8d905a..35754e086b 100644--- a/tests/llm/test_provider_adapter_contracts.py+++ b/tests/llm/test_provider_adapter_contracts.py@@ -664,6 +664,15 @@ class TestNormalizeProvider:(" QWEN ", "qwen"),("\topenai_endpoint\n", "openai_endpoint"),(" ", None),+ # Settings round-trips ship literal quotes; ``get_llm`` has always+ # resolved these, so the route checks must too.+ ('"openai_endpoint"', "openai_endpoint"),+ ("'openai_endpoint'", "openai_endpoint"),+ (' "OpenAI_Endpoint" ', "openai_endpoint"),+ (" 'ollama' ", "ollama"),+ ('""', None),+ ("''", None),+ ('" "', None),],)def test_none_safe_and_case_folding(self, raw, expected):@@ -687,6 +696,59 @@ class TestNormalizeProvider:assert chat.call_count == 1assert wrapped.base_llm is fake+ @pytest.mark.parametrize(+ "quoted", ['"openai_endpoint"', "'openai_endpoint'"]+ )+ def test_quoted_openai_endpoint_keeps_request_custom_endpoint(self, quoted):+ """A quoted ``model_provider`` must take the same openai_endpoint+ branch ``get_llm`` does: the request's ``custom_endpoint`` is used+ (not silently dropped for the stored URL) and the provider comes+ back in canonical form."""+ from local_deep_research.web.routers.research import (+ _extract_research_params,+ )++ settings_manager = MagicMock()+ settings_manager.get_setting.side_effect = lambda key, default=None: (+ "http://192.168.1.10:1234/v1"+ if key == "llm.openai_endpoint.url"+ else default+ )++ params = _extract_research_params(+ {+ "query": "q",+ "model_provider": quoted,+ "custom_endpoint": "http://192.168.1.20:5678/v1",+ },+ settings_manager,+ )++ assert params["model_provider"] == "openai_endpoint"+ assert params["custom_endpoint"] == "http://192.168.1.20:5678/v1"++ def test_quoted_openai_endpoint_falls_back_to_stored_url(self):+ """With no ``custom_endpoint`` in the request, a quoted provider+ still resolves the stored endpoint URL, like the unquoted one."""+ from local_deep_research.web.routers.research import (+ _extract_research_params,+ )++ settings_manager = MagicMock()+ settings_manager.get_setting.side_effect = lambda key, default=None: (+ "http://192.168.1.10:1234/v1"+ if key == "llm.openai_endpoint.url"+ else default+ )++ params = _extract_research_params(+ {"query": "q", "model_provider": '"openai_endpoint"'},+ settings_manager,+ )++ assert params["model_provider"] == "openai_endpoint"+ assert params["custom_endpoint"] == "http://192.168.1.10:1234/v1"+def test_non_string_model_provider_is_a_client_error(self):from local_deep_research.web.routers.research import (_extract_research_params,diff --git a/tests/security/test_egress_policy.py b/tests/security/test_egress_policy.pyindex 8035cf8586..4f125b1a2f 100644--- a/tests/security/test_egress_policy.py+++ b/tests/security/test_egress_policy.py@@ -690,6 +690,26 @@ def test_filter_engines_strict_keeps_only_primary_and_unknown():assert result == ["paperless"]+ ("raw", "expected"),+ [+ ("ollama", "ollama"),+ (' "FAISS" ', "faiss"),+ ("'pgvector'", "pgvector"),+ ('""', ""),+ (" ", ""),+ (None, ""),+ (123, ""),+ ],+)+def test_normalize_provider_key_strips_quotes_and_non_str(raw, expected):+ from local_deep_research.security.egress.policy import (+ _normalize_provider_key,+ )++ assert _normalize_provider_key(raw) == expected++def test_filter_candidates_helper_strips_by_snapshot_scope():"""filter_candidates_by_egress does the full snapshot plumbing:scope/primary extraction, context build, filter."""