def update(self, batch: Batch, *args, **kwargs) -> None:
        """Update metric with values from batch fields.

        Args:
            batch (Batch): Batch object containing required fields.
            *args: Additional positional arguments passed to parent update.
            **kwargs: Additional keyword arguments passed to parent update.

        Raises:
            ValueError: If batch is missing any required fields.
        """
        for key in self.fields:
            if getattr(batch, key, None) is None:
                # We cannot update the metric if the batch is missing required fields,
                # so we need to decrement the update count of the super class.
                self._update_count -= 1  # type: ignore[attr-defined]
                if not self.strict:
                    # If not in strict mode, skip updating the metric but don't raise an error
                    return
                # otherwise, raise an error
                if not hasattr(batch, key):
                    msg = (
                        f"Cannot update metric of type {type(self)}. Passed dataclass instance "
                        f"is missing required field: {key}"
                    )
                else:
                    msg = (
                        f"Cannot update metric of type {type(self)}. Passed dataclass instance "
                        f"does not have a value for field with name {key}."
                    )
                raise ValueError(msg)

        values = [getattr(batch, key) for key in self.fields]
        super().update(*values, *args, **kwargs)  # type: ignore[misc]
Update metric with values from batch fields.

        Args:
            batch (Batch): Batch object containing required fields.
            *args: Additional positional arguments passed to parent update.
            **kwargs: Additional keyword arguments passed to parent update.

        Raises:
            ValueError: If batch is missing any required fields.
        
src/anomalib/metrics/base.py