code: def _load_schema_for_record(data, schema=None):
      
      if schema is None:
          if '$schema' not in data:
              raise SchemaKeyNotFound(data=data)
          schema = data['$schema']
  
      if isinstance(schema, six.string_types):
          schema = load_schema(schema_name=schema)
      return schema
docs: Load the schema from a given record.
  
      Args:
          data (dict): record data.
          schema (Union[dict, str]): schema to validate against.
  
      Returns:
          dict: the loaded schema.
  
      Raises:
          SchemaNotFound: if the given schema was not found.
          SchemaKeyNotFound: if ``schema`` is ``None`` and no ``$schema`` key was
              found in ``data``.
          jsonschema.SchemaError: if the schema is invalid.