pathwaycom/pathway · error · RuntimeError

output schema validation error, received {output.as_typehint

Error message

output schema validation error, received {output.as_typehints()} vs expected {cls.output_schema.typehints()}

What it means

When a @pw.row_transformer class declares an explicit output= schema, Pathway validates that the schema generated from the transformer's output attributes is a subschema of that declared output. If an output attribute's dtype or name does not fit the declared output schema, this RuntimeError is raised (note: received/expected wording — the transformer's attributes must be assignable to `output`).

Source

Thrown at python/pathway/internals/row_transformer.py:173

        """Pseudo-random hash of its argument. Produces pointer types. Applied value-wise."""
        return ref_scalar(*args, optional=optional)

    def __init_subclass__(
        cls,
        input=Any,
        output=Any,
    ):
        cls._attributes = {
            attr.name: attr for attr in attrs_of_type(cls, AbstractAttribute)
        }
        cls.input_schema = input
        cls.output_schema = schema_from_types(
            **{attr.output_name: attr.dtype for attr in cls._output_attributes.values()}
        )
        if output is not Any and not schema.is_subschema(cls.output_schema, output):
            print(output)
            print(cls.output_schema)
            raise RuntimeError(
                f"output schema validation error, received {output.as_typehints()} vs expected {cls.output_schema.typehints()}"  # noqa
            )
        for attr in cls._attributes.values():
            attr.class_arg = cls


class AbstractAttribute(ABC):
    is_method = False
    is_output = False
    _dtype: dt.DType | None = None
    class_arg: ClassArgMeta  # lateinit by parent ClassArg

    def __init__(self, **params) -> None:
        super().__init__()
        self.params = params
        self.name = self.params.get("name", None)
        if "dtype" in self.params:
            self._dtype = dt.wrap(self.params["dtype"])

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Align the declared output schema with the transformer's output attributes: same column names, and attribute dtypes must be subtypes of the declared field types.
  2. Reorder/fix type annotations on output attributes in the ClassArg so each matches the corresponding field of output=.
  3. As a last resort omit output= and let the schema be derived from the attributes (only if downstream does not require the exact type).

Example fix

# before
@pw.row_transformer(input=In, output=Out)  # Out.value: float
class T:
    class output(pw.ClassArg):
        value: int = pw.input_method()  # mismatch

# after
@pw.row_transformer(input=In, output=Out2)  # Out2.value: int
class T:
    class output(pw.ClassArg):
        value: int = pw.input_method()
Defensive patterns

Strategy: validation

Validate before calling

import pathway as pw

def output_matches(derived: type[pw.Schema], declared: type[pw.Schema]) -> bool:
    return pw.Schema.is_subschema(derived, declared) if hasattr(pw.Schema, 'is_subschema') else declared.is_subschema_of(derived) if False else __import__('pathway.internals.schema', fromlist=['schema']).schema.is_subschema(derived, declared)

Prevention

When it happens

Trigger: Declaring @pw.row_transformer(input=InputSchema, output=OutputSchema) where an output attribute's dtype (e.g. int attribute vs float field in OutputSchema, or a missing/extra column) makes schema.is_subschema(cls.output_schema, output) false.

Common situations: Editing the transformer's output attributes without updating the declared output schema (or vice versa); version upgrades where attribute dtype inference changed (e.g. int vs float).

Related errors


AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15). Data as JSON: /api/errors/734abc48a494c9d6. Report an issue: GitHub.