{"record":{"id":"d5dc876e6b9b8369","repo":"run-llama/llama_index","slug":"query-rejected-verification-reason","errorCode":null,"errorMessage":"Query rejected: {verification.reason}","messagePattern":"Query rejected: (.+?)","errorType":"exception","errorClass":"PermissionError","httpStatus":null,"severity":"error","filePath":"llama-index-integrations/agent/llama-index-agent-agentmesh/llama_index/agent/agentmesh/query_engine.py","lineNumber":168,"sourceCode":"        # Verify invoker if required\n        if self._policy.require_verification:\n            if not invoker_card:\n                if self._data_policy.require_identity:\n                    raise PermissionError(\n                        \"Query requires invoker identity but none provided\"\n                    )\n            else:\n                verification = self.verify_invoker(invoker_card)\n                if not verification.trusted and self._policy.block_unverified:\n                    # Log blocked query\n                    if self._policy.audit_queries:\n                        record = self._create_audit_record(\n                            query_text, invoker_card, verification\n                        )\n                        record.warnings.append(\"Query blocked due to trust failure\")\n                        self._audit_log.append(record)\n\n                    raise PermissionError(f\"Query rejected: {verification.reason}\")\n\n        # Execute the underlying query\n        response = self._query_engine.query(query_bundle)\n\n        # Audit if required\n        if self._policy.audit_queries:\n            # Count results (simplified)\n            result_count = 1 if response else 0\n            record = self._create_audit_record(\n                query_text, invoker_card, verification, result_count\n            )\n            self._audit_log.append(record)\n\n        return response\n\n    async def _aquery(\n        self,\n        query_bundle: QueryBundle,","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-integrations/agent/llama-index-agent-agentmesh/llama_index/agent/agentmesh/query_engine.py#L150-L186","documentation":"Raised by AgentMeshQueryEngine.query (sync path) when invoker verification ran but came back untrusted (verification.trusted is false) and the policy is set to block unverified callers (policy.block_unverified=True). The f-string embeds verification.reason explaining why trust failed; when audit_queries is enabled a blocked-query audit record is appended to the audit log before the PermissionError propagates.","triggerScenarios":"Calling engine.query(..., invoker_card=card) where verify_invoker(card) returns trusted=False — expired card, untrusted issuer, bad signature — while policy.require_verification=True and policy.block_unverified=True. The raise happens only in the invoker_card-present branch, after the audit record is written.","commonSituations":"Expired or rotated invoker credentials; agent card signed by a CA/issuer not in the engine's trust store; clock skew making a validity window appear expired; strict production policy (block_unverified=True) applied to dev agents with self-signed cards.","solutions":["Inspect verification.reason (and the engine's audit log) to identify the exact trust failure, then fix the card (renew, re-sign with a trusted issuer, fix clock skew)","Add the invoker's issuer/CA to the engine's trusted-verifier configuration","Only if deliberate: build the engine with block_unverified=False so untrusted invokers are allowed but audited"],"exampleFix":"# before\nresp = engine.query(q, invoker_card=stale_card)  # PermissionError: Query rejected: ...\n\n# after\nfresh_card = identity.refresh_card()  # re-signed / renewed credential\nresp = engine.query(q, invoker_card=fresh_card)","handlingStrategy":"try-catch","validationCode":"def invoker_trusted(engine, card) -> bool:\n    if card is None:\n        return False\n    return engine.verify_invoker(card).trusted","typeGuard":null,"tryCatchPattern":"try:\n    resp = engine.query(q, invoker_card=card)\nexcept PermissionError as e:\n    reason = str(e).removeprefix(\"Query rejected: \")\n    logger.warning(\"untrusted invoker blocked: %s\", reason)\n    if engine._policy.audit_queries:\n        dump_audit_log(engine)  # record already appended by the engine\n    raise","preventionTips":["Verify cards with engine.verify_invoker(card) and surface the reason before querying","Automate credential renewal before expiry in long-running services","Keep the engine's trusted-issuer list in sync with mesh key rotations; review the audit log for blocked queries"],"tags":["permissions","trust-verification","query-engine","agent-mesh","audit"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}