# Buggy code
def load_data(
    self, policy_data, file_uri, validate=None, session_factory=None, config=None
):
    self.structure.validate(policy_data)

    # Use passed in policy exec configuration or default on loader
    config = config or self.policy_config

    # track policy resource types and only load if needed.
    rtypes = set(self.structure.get_resource_types(policy_data))

    missing = load_resources(list(rtypes))
    if missing:
        self._handle_missing_resources(policy_data, missing)

    if validate is not False or (validate is None and self.default_schema_validate):
        errors = self.validator.validate(policy_data, tuple(rtypes))
        if errors:
            raise PolicyValidationError(
                "Failed to validate policy %s\n %s\n" % (errors[1], errors[0])
            )

    collection = self.collection_class.from_data(policy_data, config, session_factory)

    # non schema validation of policies isnt optional its
    # become a lazy initialization point for resources.
    #
    # it would be good to review where we do validation
    # as we also have to do after provider policy
    # initialization due to the region expansion.
    #
    # ie we should defer this to callers
    # [p.validate() for p in collection]
    return collection


# Traceback (RuntimeError)
[ERROR] RuntimeError: missing jsonschema dependency
Traceback (most recent call last):
File "/var/task/custodian_policy.py", line 4, in run
return handler.dispatch_event(event, context)
File "/var/task/c7n/handler.py", line 175, in dispatch_event
p.validate()
File "/var/task/c7n/policy.py", line 1047, in validate
f.validate()
File "/var/task/c7n/filters/missing.py", line 49, in validate
collection = PolicyLoader(
File "/var/task/c7n/loader.py", line 136, in load_data
errors = self.validator.validate(policy_data, tuple(rtypes))
File "/var/task/c7n/loader.py", line 47, in validate
self.gen_schema(tuple(sorted(resource_types)))
File "/var/task/c7n/loader.py", line 74, in gen_schema
self.validator = v = self._gen_schema(resource_types)
File "/var/task/c7n/loader.py", line 82, in _gen_schema
raise RuntimeError("missing jsonschema dependency")

# Fixed code
def load_data(
    self, policy_data, file_uri, validate=None, session_factory=None, config=None
):
    self.structure.validate(policy_data)

    # Use passed in policy exec configuration or default on loader
    config = config or self.policy_config

    # track policy resource types and only load if needed.
    rtypes = set(self.structure.get_resource_types(policy_data))

    missing = load_resources(list(rtypes))
    if missing:
        self._handle_missing_resources(policy_data, missing)

    if schema and (
        validate is not False or (validate is None and self.default_schema_validate)
    ):
        errors = self.validator.validate(policy_data, tuple(rtypes))
        if errors:
            raise PolicyValidationError(
                "Failed to validate policy %s\n %s\n" % (errors[1], errors[0])
            )

    collection = self.collection_class.from_data(policy_data, config, session_factory)

    # non schema validation of policies isnt optional its
    # become a lazy initialization point for resources.
    #
    # it would be good to review where we do validation
    # as we also have to do after provider policy
    # initialization due to the region expansion.
    #
    # ie we should defer this to callers
    # [p.validate() for p in collection]
    return collection