def METHOD_NAME(cls, values: dict) -> dict:
    infer_cells = values.get('infer_cells')
    has_bg_class_id = values.get('background_class_id') is not None
    if infer_cells and not has_bg_class_id:
        raise ConfigError(
            'background_class_id is required if infer_cells=True.')
    return values