def assert_valid(sysmeta_pyxb, pid):
    """Validate file at {sciobj_path} against schema selected via formatId and raise
    InvalidRequest if invalid.

    Validation is only performed when:

    - SciMeta validation is enabled
    - and Object size is below size limit for validation
    - and formatId designates object as a Science Metadata object which is recognized
      and parsed by DataONE CNs
    - and XML Schema (XSD) files for formatId are present on local system

    """
    if not (_is_validation_enabled() and _is_installed_scimeta_format_id(sysmeta_pyxb)):
        return

    if _is_above_size_limit(sysmeta_pyxb):
        if _is_action_accept():
            return
        else:
            raise d1_common.types.exceptions.InvalidRequest(
                0,
                'Science Metadata file is above size limit for validation and this '
                'node has been configured to reject unvalidated Science Metadata '
                'files. For more information, see the SCIMETA_VALIDATE* settings. '
                'size={} size_limit={}'.format(
                    sysmeta_pyxb.size, django.conf.settings.SCIMETA_VALIDATION_MAX_SIZE
                ),
            )

    with d1_gmn.app.sciobj_store.open_sciobj_file_by_pid_ctx(pid) as sciobj_file:
        try:
            d1_scimeta.xml_schema.validate(sysmeta_pyxb.formatId, sciobj_file.read())
        except d1_scimeta.xml_schema.SciMetaValidationError as e:
            raise d1_common.types.exceptions.InvalidRequest(0, str(e))