Comfy-Org/ComfyUI · error · Exception

Response validation failed for {getattr(response_model, '__n

Error message

Response validation failed for {getattr(response_model, '__name__', response_model)}: {e}

What it means

A remote API response body failed Pydantic validation against the expected response model. The helper _validate_or_raise calls response_model.model_validate(payload) and re-raises as a generic Exception when the payload does not satisfy the model's schema. This almost always means the upstream service returned a different shape than the node's Pydantic model declares (renamed/missing fields, changed types, or an error payload returned with HTTP 200).

Source

Thrown at comfy_api_nodes/util/client.py:981

                        else int(time.monotonic() - start_time)
                    ),
                    estimated_total=cfg.estimated_total,
                    price=extracted_price,
                    is_queued=False,
                    processing_elapsed_seconds=final_elapsed_seconds,
                )


def _validate_or_raise(response_model: type[M], payload: Any) -> M:
    try:
        return response_model.model_validate(payload)
    except Exception as e:
        logging.error(
            "Response validation failed for %s: %s",
            getattr(response_model, "__name__", response_model),
            e,
        )
        raise Exception(
            f"Response validation failed for {getattr(response_model, '__name__', response_model)}: {e}"
        ) from e


def _wrap_model_extractor(
    response_model: type[M],
    extractor: Callable[[M], Any] | None,
) -> Callable[[dict[str, Any]], Any] | None:
    """Wrap a typed extractor so it can be used by the dict-based poller.
    Validates the dict into `response_model` before invoking `extractor`.
    Uses a small per-wrapper cache keyed by `id(dict)` to avoid re-validating
    the same response for multiple extractors in a single poll attempt.
    """
    if extractor is None:
        return None
    _cache: dict[int, M] = {}

    def _wrapped(d: dict[str, Any]) -> Any:

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Read the logged validation detail (the message includes the Pydantic error, e.g. 'Field required', 'Input should be a valid integer') to identify the exact field mismatch.
  2. Check the provider's API changelog / openapi spec for the failing endpoint and compare against the Pydantic model named in the message.
  3. Update ComfyUI (and comfy_api_nodes) to the latest version, which usually tracks the current API schema.
  4. If you maintain the node, adjust the response model (make the field Optional, add a default, or rename it) to match the observed payload, keeping validation strict for the rest of the schema.

Example fix

// before
class GenerationResponse(BaseModel):
    video_url: str  # upstream renamed to output.video_url

// after
class GenerationOutput(BaseModel):
    video_url: str

class GenerationResponse(BaseModel):
    output: GenerationOutput | None = None
    video_url: str | None = None
    @property
    def resolved_video_url(self) -> str:
        return self.video_url or (self.output.video_url if self.output else "")
Defensive patterns

Strategy: try-catch

Try / catch

try:
    result = await node_api.call(...)
except Exception as e:
    if 'Response validation failed' in str(e):
        # log raw payload via request_logger, then surface a clear message
        raise RuntimeError(f'API schema mismatch: {e}') from e
    raise

Prevention

When it happens

Trigger: Any Comfy API-node request whose response is validated by _validate_or_raise in comfy_api_nodes/util/client.py: an upstream API ships a schema change (field renamed, null where a string was required, nested object flattened), or the service returns an HTML/JSON error document with a 200 status that does not match the model.

Common situations: Upstream provider deploys a breaking API change; API version pinned in the node no longer matches the live endpoint; a proxy or firewall rewrites the response body; the response model in the local ComfyUI install is older/newer than the API contract.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/24d2215b4c501293. Report an issue: GitHub.