Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

Sanitize cross-system capture errors in returned payload

KaifAhmad1a785247b9872
diff --git a/semantica/context/agent_context.py b/semantica/context/agent_context.py
index 9d4a5230..8ee178dd 100644
--- a/semantica/context/agent_context.py
+++ b/semantica/context/agent_context.py
@@ -1989,8 +1989,14 @@ class AgentContext:
payload["records_found"] = 0
payload["records"] = []
except Exception as e:
+ self.logger.warning(
+ "Cross-system input capture failed for system=%s entity_id=%s: %s",
+ system,
+ entity_id,
+ str(e),
+ )
payload["status"] = "capture_failed"
- payload["error"] = str(e)
+ payload["error"] = "internal_capture_error"
payload["records_found"] = 0
payload["records"] = []
diff --git a/tests/context/test_agent_context_decisions.py b/tests/context/test_agent_context_decisions.py
index 4a817451..e0cb60f3 100644
--- a/tests/context/test_agent_context_decisions.py
+++ b/tests/context/test_agent_context_decisions.py
@@ -246,6 +246,22 @@ class TestAgentContextDecisions:
assert context[system]["system_name"] == system
assert "captured_at" in context[system]
assert context[system]["status"] == "captured"
+
+ def test_capture_cross_system_inputs_sanitizes_errors(
+ self, agent_context_with_decisions, mock_knowledge_graph
+ ):
+ """Test capture errors are sanitized in returned payload."""
+ mock_knowledge_graph.execute_query.side_effect = RuntimeError(
+ "backend connection failed: sensitive details"
+ )
+
+ context = agent_context_with_decisions.capture_cross_system_inputs(
+ ["salesforce"], "customer_001"
+ )
+
+ assert context["salesforce"]["status"] == "capture_failed"
+ assert context["salesforce"]["error"] == "internal_capture_error"
+ assert "sensitive" not in context["salesforce"]["error"]
def test_backward_compatibility(self, mock_vector_store, mock_knowledge_graph):
"""Test backward compatibility when decision tracking is not explicitly set."""