microsoft/semantic-kernel · error · FunctionExecutionException
This `RestApiPayload` instance is frozen and cannot be modif
Error message
This `RestApiPayload` instance is frozen and cannot be modified.
What it means
`RestApiPayload._throw_if_frozen` raises `FunctionExecutionException` if any setter is invoked after `freeze()` set `_is_frozen = True`. Because `freeze()` also calls `property.freeze()` on every nested property, the whole payload tree becomes immutable once an owning operation is frozen after REST-function registration.
Source
Thrown at python/semantic_kernel/connectors/openapi_plugin/models/rest_api_payload.py:37
schema: str | None = None,
):
"""Initialize the RestApiPayload."""
self._media_type = media_type
self._properties = properties
self._description = description
self._schema = schema
self._is_frozen = False
def freeze(self):
"""Make the instance immutable and freeze properties."""
self._is_frozen = True
for property in self._properties:
property.freeze()
def _throw_if_frozen(self):
"""Raise an exception if the object is frozen."""
if self._is_frozen:
raise FunctionExecutionException("This `RestApiPayload` instance is frozen and cannot be modified.")
@property
def media_type(self):
"""Get the media type of the payload."""
return self._media_type
@media_type.setter
def media_type(self, value: str):
self._throw_if_frozen()
self._media_type = value
@property
def description(self):
"""Get the description of the payload."""
return self._description
@description.setter
def description(self, value: str | None):View on GitHub (pinned to c028a0c7dc)
Solutions
- Edit the source OpenAPI spec and re-run `create_functions_from_openapi` so a fresh (unfrozen) payload is built.
- Construct a new `RestApiPayload(...)` with the desired fields and assign it before registration.
- Perform any payload mutation prior to the `operation.freeze()` call in the registration pipeline.
- Avoid reusing a payload object across multiple registered operations.
Example fix
// before
kernel.add_openapi_plugin(...)
operation.payload.media_type = "application/xml" # raises 1481
// after
spec["paths"]["/x"]["post"]["requestBody"]["content"] = {"application/xml": {...}}
kernel.add_openapi_plugin_from_spec(spec, ...) Defensive patterns
Strategy: validation
Validate before calling
def assert_payload_mutable(payload) -> None:
if getattr(payload, "_is_frozen", False):
raise RuntimeError("RestApiPayload is frozen; reconstruct it instead.")
assert_payload_mutable(operation.payload) Type guard
def is_unfrozen_payload(obj) -> bool:
return hasattr(obj, "_is_frozen") and not obj._is_frozen Try / catch
from semantic_kernel.exceptions import FunctionExecutionException
try:
operation.payload.media_type = "application/json"
except FunctionExecutionException as e:
if "frozen" in str(e):
# rebuild from spec instead
raise RuntimeError("Re-parse the spec to change payload media type") from e
raise Prevention
- Edit the request body in the source spec, not the parsed payload.
- Never share a parsed operation between two kernel functions.
- Deep-copy parsed trees before mutating in tests.
- Assert media types in the spec before registration.
When it happens
Trigger: Setting `media_type` or any other payload property after the operation owning the payload has been frozen. The freeze cascade is triggered by `RestApiOperation.freeze()` (called at the end of `_create_rest_api_operation` registration in `create_rest_api_operations` / inside `create_functions_from_openapi`).
Common situations: Editing `operation.payload` (e.g. swapping the media type or rewriting properties) after the plugin was already added to the kernel; sharing a parsed operation between two kernel functions and mutating it for the second one; test code that post-processes parsed payloads.
Related errors
- This `RestApiParameter` instance is frozen and cannot be mod
- This instance is frozen and cannot be modified.
- The `RestApiOperation` instance with id {self.id} is frozen
- Invalid server_url_override: {self.server_url_override}
- Either `openapi_document_path` or `openapi_parsed_spec` must
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/65c14d6b8b9b87ed.
Report an issue: GitHub.