code: def validate_instance(
      instance: pa.RecordBatch,
      options: stats_options.StatsOptions,
      environment: Optional[str] = None,
  ) -> anomalies_pb2.Anomalies:
      """Validates a batch of examples against the schema provided in `options`.
  
      If an optional `environment` is specified, the schema is filtered using the
      `environment` and the `instance` is validated against the filtered schema.
  
      Args:
        instance: A batch of examples in the form of an Arrow RecordBatch.
        options: `tfdv.StatsOptions` for generating data statistics. This must
          contain a schema.
        environment: An optional string denoting the validation environment. Must be
          one of the default environments specified in the schema. In some cases
          introducing slight schema variations is necessary, for instance features
          used as labels are required during training (and should be validated), but
          are missing during serving. Environments can be used to express such
          requirements. For example, assume a feature named 'LABEL' is required for
          training, but is expected to be missing from serving. This can be
          expressed by defining two distinct environments in the schema: ["SERVING",
          "TRAINING"] and associating 'LABEL' only with environment "TRAINING".
  
      Returns:
        An Anomalies protocol buffer.
  
      Raises:
        ValueError: If `options` is not a StatsOptions object.
        ValueError: If `options` does not contain a schema.
      """
      if not isinstance(options, stats_options.StatsOptions):
          raise ValueError("options must be a StatsOptions object.")
      if options.schema is None:
          raise ValueError("options must include a schema.")
      feature_statistics_list = (
          stats_impl.generate_statistics_in_memory(instance, options)
      )
      anomalies = validate_statistics(
          feature_statistics_list, options.schema, environment
      )
      if anomalies.anomaly_info:
          # If anomalies were found, remove anomaly types that do not apply on a
          # per-example basis from the Anomalies proto.
          anomalies_util.remove_anomaly_types(
              anomalies, _GLOBAL_ONLY_ANOMALY_TYPES
          )
      return anomalies
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import itertools
  import logging
  from typing import Callable, Iterable, List, Optional, Text, Tuple, Set
  import apache_beam
  import pyarrow
  import tensorflow
  from tensorflow_data_validation import constants
  from tensorflow_data_validation import types
  from tensorflow_data_validation.anomalies.proto import custom_validation_config_pb2
  from tensorflow_data_validation.anomalies.proto import validation_config_pb2
  from tensorflow_data_validation.anomalies.proto import validation_metadata_pb2
  from tensorflow_data_validation.api import validation_options
  from tensorflow_data_validation.pywrap.tensorflow_data_validation_extension import validation
  from tensorflow_data_validation.skew import feature_skew_detector
  from tensorflow_data_validation.skew.protos import feature_skew_results_pb2
  from tensorflow_data_validation.statistics import stats_impl
  from tensorflow_data_validation.statistics import stats_options
  from tensorflow_data_validation.utils import anomalies_util
  from tensorflow_data_validation.utils import slicing_util
  from tensorflow_data_validation.utils import stats_util
  from tensorflow_metadata.proto.v0 import anomalies_pb2
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 10 for calling a global function with example usage: validate_instance(instance, options, environment) and returns: anomalies