def set_attr_forbid_unknown(cls):
    """Override the __setattr__ method of a dataclass `cls` to forbid setting fields that do not exist in `cls`"""

    def __setattr__(self, key, value):
        if key not in self.__class__.__dataclass_fields__:
            raise AttributeError(
                f"Class {self.__class__} has no attribute {key}. "
                f"Available fields: {', '.join(self.__class__.__dataclass_fields__.keys())}"
            )
        else:
            return super(cls, self).__setattr__(key, value)

    return __setattr__