Data handling (agents)

Data handling refers to the policies and mechanisms for how agents collect, process, store, and transmit sensitive information. In agentic systems, proper data handling ensures that user information, API credentials, business data, and other sensitive materials are managed securely throughout their lifecycle—from initial collection through processing, storage, transmission, and eventual deletion.

Why it matters

Effective data handling is critical for several interconnected reasons:

Regulatory compliance — Organizations deploying agents must comply with data protection regulations like GDPR, CCPA, HIPAA, and industry-specific standards. Non-compliance can result in penalties reaching millions of dollars, with GDPR fines up to 4% of annual global revenue. Agents that collect personally identifiable information (PII), health records, or financial data require documented data handling procedures to satisfy audit requirements.

Data minimization — Collecting only necessary data reduces attack surface and compliance burden. Agents often have broad access to systems and can observe sensitive information incidentally during task execution. Without explicit data minimization policies, agents may log, cache, or transmit data that isn't required for their function, creating unnecessary risk.

Breach prevention — Data breaches involving agent systems can expose credentials, customer information, or proprietary business data. The average cost of a data breach exceeded $4.45 million in 2023. Agents that interact with multiple systems become attractive targets because they often maintain credentials for various services and process data across security boundaries.

Concrete examples

Data classification levels

Implement tiered classification to apply appropriate controls:

Public data — Marketing content, public API documentation. Agents can cache indefinitely, transmit over standard connections, and log freely.

Internal data — Employee directories, internal wikis, non-sensitive business metrics. Agents should encrypt in transit, apply session-based caching, and redact from logs sent to third-party services.

Confidential data — Customer PII, financial records, health information. Agents must encrypt in transit and at rest, implement strict access controls, apply automatic redaction, and enforce short retention periods.

Restricted data — Authentication credentials, encryption keys, trade secrets. Agents should never log these values, must use encrypted memory storage, require elevated permissions for access, and purge immediately after use.

Encryption in transit and at rest

In transit — All agent communication with external services should use TLS 1.3 or higher. For internal service communication, mutual TLS (mTLS) provides bidirectional authentication. API credentials should never appear in URLs where they might be logged by proxies or CDNs.

At rest — Persistent agent memory, conversation logs, and cached data require encryption. Use AES-256 for file encryption and database-level encryption for structured storage. Encryption keys should be managed through dedicated services like AWS KMS, Azure Key Vault, or HashiCorp Vault—never hardcoded or stored alongside encrypted data.

Data retention policies

Session-scoped data — Authentication tokens, temporary credentials, and working memory should be purged when agent sessions terminate. Maximum retention: duration of session plus grace period for crash recovery (typically < 1 hour).

Short-term retention — Conversation logs for debugging and model fine-tuning. Retention: 7-30 days with automatic deletion. PII should be redacted before storage.

Long-term retention — Anonymized analytics, aggregate metrics, audit trails for compliance. Retention: as required by regulations (often 1-7 years). Individual identifiers must be removed or pseudonymized.

No retention — Sensitive credentials, credit card numbers, health records (unless specifically required). These should be processed in memory and never persisted.

Common pitfalls

Over-collection — Agents designed to be "helpful" may capture excessive context to improve performance. A customer service agent might log entire conversation histories including PII, when only anonymized interaction patterns are needed for improvement. Implement collection policies that explicitly define what data is necessary versus merely useful.

Insecure transmission — Agents communicating with multiple services may fall back to HTTP for internal APIs or development endpoints. A single unencrypted connection can expose session tokens, API keys, or customer data. Enforce TLS for all connections and fail closed when secure transmission is unavailable.

Indefinite retention — Without explicit deletion policies, agent systems accumulate data indefinitely. Cached API responses, debug logs, and temporary files persist far beyond their useful life. One organization discovered their agent framework had retained 18 months of conversation logs containing customer PII, despite only needing 7 days for debugging purposes.

Logging sensitive data — Verbose logging for debugging often captures sensitive information. Logs sent to third-party observability platforms may include API keys in headers, PII in request bodies, or credentials in error messages. Implement automatic redaction for known patterns (credit cards, SSNs, API keys) and review log outputs before enabling third-party integrations.

Inadequate access controls — Agent data stores often lack the same access controls as production databases. Development teams may have broad access to agent logs and caches that contain production data. Apply principle of least privilege to agent infrastructure with the same rigor as production systems.

Implementation

Data lifecycle management

Implement distinct handling for each lifecycle phase:

Collection — Define allowlists of collectible data types. For web agents, specify which DOM elements or page sections can be read. For API agents, enumerate which response fields are captured. Use schema validation to reject unexpected data types.

Processing — Apply transformations immediately at collection boundaries. Hash or tokenize identifiers, redact PII, truncate large payloads. Processing rules should be declarative and auditable, not scattered through agent code.

Storage — Separate storage tiers by data classification. High-sensitivity data requires encrypted databases with field-level encryption for specific columns. Implement automatic expiration using database TTL features or scheduled purge jobs.

Transmission — Use service meshes or API gateways to enforce encryption and authentication policies uniformly. Tag outbound requests with data classification levels to enable network-level policy enforcement.

Deletion — Implement both logical deletion (mark as deleted, purge later) and physical deletion (immediate removal). Provide user-initiated deletion capabilities for GDPR compliance. Verify deletion with auditable logs showing what was removed and when.

Access controls

Role-based access — Define roles (agent-runtime, agent-developer, data-analyst) with specific permissions to agent data stores. The runtime role should have minimal read/write permissions for operational data only.

Attribute-based access — Control access based on data classification, user context, and request purpose. An agent may access confidential customer data only when processing a request from that specific customer.

Audit logging — Record all access to sensitive agent data with sufficient detail for forensic analysis: who accessed what data, when, from where, and why. Retention for audit logs typically exceeds operational data retention (often 1-7 years).

Encryption strategies

Encryption at rest — For databases, enable transparent data encryption (TDE) for baseline protection. Add application-level encryption for highly sensitive fields using envelope encryption: encrypt data with data encryption keys (DEKs), encrypt DEKs with key encryption keys (KEKs) stored in key management systems.

Encryption in transit — Enforce TLS 1.3 with strong cipher suites. Disable TLS 1.0/1.1 and weak ciphers like CBC-mode algorithms. For internal service communication, implement certificate-based mutual authentication.

Encryption in use — For extremely sensitive scenarios, consider confidential computing technologies (Intel SGX, AMD SEV, AWS Nitro Enclaves) that encrypt data even while being processed in memory.

Key management — Rotate encryption keys on defined schedules (quarterly for high-sensitivity data). Implement key versioning to support re-encryption. Store keys in hardware security modules (HSMs) or cloud key management services with strict access policies.

Key metrics to track

Data exposure incidents Unauthorized access events / Quarter Target: < 1 incident per 100,000 agent sessions Track both external attacks and internal unauthorized access. Trend over time should decrease as controls mature.

Encryption coverage Encrypted sensitive data / Total sensitive data × 100 Target: 100% of confidential and restricted data Measure separately for databases, file storage, message queues, and logs.

Retention compliance Data stores meeting retention policy / Total data stores × 100 Target: > 99% Measure data age in each storage system against policy limits. Non-compliant data stores indicate failed deletion processes or missing policies.

Redaction accuracy (false negatives) Sensitive data missed / Total sensitive data instances × 100 Target: < 1% for common PII patterns Measure separately for emails, SSNs, credit cards, API keys.

Access control violations Denied access attempts / Total access attempts × 1000 Baseline: 5-10 violations per 1000 requests Sustained high rates suggest misconfigured permissions or attack attempts.

Time to deletion Σ(Actual deletion time - Policy deletion time) / Deletion requests Target: < 30 days for user-initiated deletions (GDPR) Target: < 24 hours for automated retention policies

Related concepts

  • PII redaction — Automated techniques for removing personally identifiable information from agent logs and outputs
  • Least privilege — Access control principle that limits agent permissions to minimum necessary scope
  • Session scope — Boundaries defining the lifecycle and data retention period for agent interactions
  • Auth models — Authentication and authorization frameworks for controlling agent access to protected resources