microsoft/semantic-kernel · error · ValueError

Invalid server_url_override: {self.server_url_override}

Error message

Invalid server_url_override: {self.server_url_override}

What it means

`OpenAPIFunctionExecutionParameters.model_post_init` validates `server_url_override`: when it is non-empty it is run through `urlparse` and the code requires both a `scheme` and a `netloc`. A bare host, a path, or a typo'd URL (missing `http(s)://`) raises a raw `ValueError`. This guards the SSRF-prevention configuration surface before any request is sent.

Source

Thrown at python/semantic_kernel/connectors/openapi_plugin/openapi_function_execution_parameters.py:79

        ),
    )
    allow_private_network_access: bool = Field(
        False,
        description=(
            "Whether OpenAPI operation requests may target private, loopback, link-local, or otherwise "
            "non-public IP addresses. Disabled by default to prevent SSRF."
        ),
    )

    def model_post_init(self, __context: Any) -> None:
        """Post initialization method for the model."""
        from semantic_kernel.connectors.openapi_plugin.server_url_validator import ServerUrlValidationOptions
        from semantic_kernel.utils.telemetry.user_agent import HTTP_USER_AGENT

        if self.server_url_override:
            parsed_url = urlparse(self.server_url_override)
            if not parsed_url.scheme or not parsed_url.netloc:
                raise ValueError(f"Invalid server_url_override: {self.server_url_override}")

        ServerUrlValidationOptions(allowed_base_urls=self.server_url_validation_allowed_base_urls)

        if not self.user_agent:
            self.user_agent = HTTP_USER_AGENT

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Provide a full absolute URL including scheme, e.g. `https://api.example.com`.
  2. Normalize the value before passing it: `server_url_override = f"https://{host}"` if you only have a host.
  3. Validate the env/config value with `urllib.parse.urlparse` in your own config loader and fail fast with a clearer message.
  4. Leave `server_url_override` unset and rely on the spec's own `servers` block if you do not need to override.

Example fix

# before
params = OpenAPIFunctionExecutionParameters(server_url_override="api.example.com")  # raises 1483

# after
params = OpenAPIFunctionExecutionParameters(server_url_override="https://api.example.com")
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlparse

def normalize_server_url_override(value: str | None) -> str | None:
    if not value:
        return None
    parsed = urlparse(value)
    if not parsed.scheme or not parsed.netloc:
        # add https:// if the user passed a bare host
        if "." in value and "://" not in value:
            return f"https://{value}"
        raise ValueError(f"server_url_override must be an absolute URL, got: {value!r}")
    return value

override = normalize_server_url_override(cfg.get("API_BASE"))
params = OpenAPIFunctionExecutionParameters(server_url_override=override)

Type guard

from urllib.parse import urlparse

def is_absolute_url(value: str) -> bool:
    p = urlparse(value)
    return bool(p.scheme in ("http", "https") and p.netloc)

Try / catch

# model_post_init raises ValueError at construction time
try:
    params = OpenAPIFunctionExecutionParameters(server_url_override=raw)
except ValueError as e:
    raise ConfigError(f"Bad server_url_override: {raw!r} ({e})") from e

Prevention

When it happens

Trigger: Constructing `OpenAPIFunctionExecutionParameters(server_url_override=...)` with a value like `"example.com"`, `"localhost:8080"`, `"/api/v1"`, or `"ftp://x"`-style fragments that lack a parseable scheme/netloc. Pydantic runs `model_post_init` at construction, so the error fires immediately on instantiation.

Common situations: Copy-pasting a base URL without the scheme; pulling a host from an env var that omits `https://`; switching from a config field that held just a hostname to one that expected a full URL; CI where the override is templated incorrectly.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/88099563bb286355. Report an issue: GitHub.