This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: otel-genai-payload-pii-redaction-pipeline-guardrail

OTel GenAI Semantic Conventions Payload PII Redaction Pipeline Guardrail

Enforces pre-ingestion PII scrubbing and strict GenAI semantic convention enforcement across distributed tracing pipelines. Prevents raw user inputs, completion payloads, and dynamic prompt templates from reaching multi-tenant telemetry backends without cryptographically assured token masking and OpenTelemetry Collector transform processor validation.

Prohibited Anti-Pattern: Leaking Unsanitized GenAI Prompt and Completion Payloads Directly into Multi-Tenant Observability Backends

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: OTel GenAI Semantic Conventions Payload PII Redaction Pipeline Guardrail - Enforces pre-ingestion PII scrubbing and strict GenAI semantic convention enforcement across distributed tracing pipelines. Prevents raw user inputs, completion payloads, and dynamic prompt templates from reaching multi-tenant telemetry backends without cryptographically assured token masking and OpenTelemetry Collector transform processor validation.
globs: otelcol/**/*.yaml, otelcol/**/*.yml, src/observability/**/*.{ts,js}, src/telemetry/**/*.{ts,js}, src/llm/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/otel-genai-payload-pii-redaction-pipeline-guardrail"
---

# OTel GenAI Semantic Conventions Payload PII Redaction Pipeline Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Leaking Unsanitized GenAI Prompt and Completion Payloads Directly into Multi-Tenant Observability Backends

## System Constraints
You are a Principal Observability and Security Architect enforcing OpenTelemetry GenAI Semantic Conventions and pre-ingestion PII redaction. You must mandate that raw prompt-completion pairs (specifically `gen_ai.prompt` and `gen_ai.completion` attributes, or span events matching `gen_ai.user.message` and `gen_ai.choice`) are sanitized at both SDK emission and within the OpenTelemetry Collector transformation pipeline before persistent multi-tenant storage. Never permit unmasked credentials, SSNs, credit cards, emails, or HIPAA/GDPR identifiers to populate trace spans.

## Strict Guidelines
- Engineers MUST ALWAYS configure the OpenTelemetry Collector `transform` or `redaction` processor in the trace pipeline to enforce regex-based masking on `gen_ai.content.prompt` and `gen_ai.content.completion` attributes.
- Engineers MUST NOT emit raw user input or raw model completions directly to trace spans without applying local context-aware sanitization filters at the application boundary.
- Code SHOULD adhere strictly to OpenTelemetry GenAI Semantic Conventions (v1.28.0+), using standard span names (`invoke_model {model_name}`, `{operation_name} {model_name}`) and standard attributes (`gen_ai.system`, `gen_ai.request.model`, `gen_ai.response.model`).
- Services MUST route trace telemetry through an intermediate, hardened OpenTelemetry Gateway Collector prior to downstream export to third-party vendors or shared multi-tenant SaaS backends.
- Components NEVER attach unmasked authorization headers, system prompt secrets, session cookies, or raw input embeddings to trace span attributes or span event logs.

## Bad vs Good Implementations
### Application-Level Span Creation: Raw vs. Sanitized GenAI Prompt Events

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly logging unredacted prompt and completion payloads introduces high-risk PII/PHI leakage into tracing backends, violating GDPR/HIPAA compliance and enterprise data isolation standards.
```typescript
import { trace } from '@opentelemetry/api';

const tracer = trace.getTracer('llm-service');

export async function executePrompt(promptText: string): Promise<string> {
  return tracer.startActiveSpan('chat_completion', async (span) => {
    // ANTI-PATTERN: Emitting raw user prompt and completions directly into span attributes
    span.setAttribute('gen_ai.prompt', promptText);
    const completion = await callLLM(promptText);
    span.setAttribute('gen_ai.completion', completion);
    span.end();
    return completion;
  });
}
```

#### Production Standard (Correct)
> **Standard**: Adheres to OpenTelemetry GenAI semantic naming standards, redacts high-risk PII at the boundary, and sets canonical error statuses.
```typescript
import { trace, SpanStatusCode } from '@opentelemetry/api';
import { sanitizePII } from './security/redactor';

const tracer = trace.getTracer('llm-service', '1.0.0');

export async function executePrompt(modelName: string, promptText: string): Promise<string> {
  // Standardized GenAI semantic span name
  return tracer.startActiveSpan(`chat ${modelName}`, async (span) => {
    try {
      span.setAttributes({
        'gen_ai.system': 'openai',
        'gen_ai.request.model': modelName,
        'gen_ai.operation.name': 'chat',
        // Invariant: Scrub application-level dynamic payload before span emission
        'gen_ai.content.prompt': sanitizePII(promptText),
      });

      const completion = await callLLM(promptText);

      span.setAttribute('gen_ai.content.completion', sanitizePII(completion));
      span.setStatus({ code: SpanStatusCode.OK });
      return completion;
    } catch (error) {
      span.recordException(error as Error);
      span.setStatus({ code: SpanStatusCode.ERROR, message: (error as Error).message });
      throw error;
    } finally {
      span.end();
    }
  });
}
```

### OpenTelemetry Collector Pipeline: Unsafe Pass-Through vs. OTTL Transform Redaction

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Lacks the transform processor; any sensitive PII missed by client-side SDKs will pass directly to multi-tenant backends unmasked.
```yaml
# ANTI-PATTERN: otel-collector-config.yaml missing payload sanitization pipeline
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  batch:
    send_batch_size: 1024

exporters:
  otlp/vendor:
    endpoint: ingress.observability-vendor.com:4317

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/vendor]
```

#### Production Standard (Correct)
> **Standard**: Employs OpenTelemetry Transformation Language (OTTL) within the collector transform processor to guarantee payload scrubbing prior to multi-tenant outbound export.
```yaml
# PRODUCTION INVARIANT: otel-collector-config.yaml with defensive OTTL redaction
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  batch:
    send_batch_size: 1024
  transform/pii_redaction:
    error_mode: ignore
    trace_statements:
      - context: span
        statements:
          # Mask SSN patterns
          - replace_pattern(attributes["gen_ai.content.prompt"], "\\b\\d{3}-\\d{2}-\\d{4}\\b", "[REDACTED_SSN]")
          - replace_pattern(attributes["gen_ai.content.completion"], "\\b\\d{3}-\\d{2}-\\d{4}\\b", "[REDACTED_SSN]")
          # Mask Email patterns
          - replace_pattern(attributes["gen_ai.content.prompt"], "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}", "[REDACTED_EMAIL]")
          - replace_pattern(attributes["gen_ai.content.completion"], "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}", "[REDACTED_EMAIL]")

exporters:
  otlp/vendor:
    endpoint: ingress.observability-vendor.com:4317

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [transform/pii_redaction, batch]
      exporters: [otlp/vendor]
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: OTel GenAI Semantic Conventions Payload PII Redaction Pipeline Guardrail

OTel GenAI Semantic Conventions Payload PII Redaction Pipeline Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces pre-ingestion PII scrubbing and strict GenAI semantic convention enforcement across distributed tracing pipelines. Prevents raw user inputs, completion payloads, and dynamic prompt templates from reaching multi-tenant telemetry backends without cryptographically assured token masking and OpenTelemetry Collector transform processor validation. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Leaking Unsanitized GenAI Prompt and Completion Payloads Directly into Multi-Tenant Observability Backends Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftLeaking Unsanitized GenAI Prompt and Completion Payloads Directly into Multi-Tenant Observability BackendsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS configure the OpenTelemetry Collector `transform` or `redaction` processor in the trace pipeline to enforce regex-based masking on `gen_ai.content.prompt` and `gen_ai.content.completion` attributes.

Engineers MUST ALWAYS configure the OpenTelemetry Collector `transform` or `redaction` processor in the trace pipeline to enforce regex-based masking on `gen_ai.content.prompt` and `gen_ai.content.completion` attributes.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT emit raw user input or raw model completions directly to trace spans without applying local context-aware sanitization filters at the application boundary.

Engineers MUST NOT emit raw user input or raw model completions directly to trace spans without applying local context-aware sanitization filters at the application boundary.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Code SHOULD adhere strictly to OpenTelemetry GenAI Semantic Conventions (v1.28.0+), using standard span names (`invoke_model {model_name}`, `{operation_name} {model_name}`) and standard attributes (`gen_ai.system`, `gen_ai.request.model`, `gen_ai.response.model`).

Code SHOULD adhere strictly to OpenTelemetry GenAI Semantic Conventions (v1.28.0+), using standard span names (`invoke_model {model_name}`, `{operation_name} {model_name}`) and standard attributes (`gen_ai.system`, `gen_ai.request.model`, `gen_ai.response.model`).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST route trace telemetry through an intermediate, hardened OpenTelemetry Gateway Collector prior to downstream export to third-party vendors or shared multi-tenant SaaS backends.

Services MUST route trace telemetry through an intermediate, hardened OpenTelemetry Gateway Collector prior to downstream export to third-party vendors or shared multi-tenant SaaS backends.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER attach unmasked authorization headers, system prompt secrets, session cookies, or raw input embeddings to trace span attributes or span event logs.

Components NEVER attach unmasked authorization headers, system prompt secrets, session cookies, or raw input embeddings to trace span attributes or span event logs.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is OTel GenAI Semantic Conventions Payload PII Redaction Pipeline Guardrail critical for AI coding assistants?

Enforces pre-ingestion PII scrubbing and strict GenAI semantic convention enforcement across distributed tracing pipelines. Prevents raw user inputs, completion payloads, and dynamic prompt templates from reaching multi-tenant telemetry backends without cryptographically assured token masking and OpenTelemetry Collector transform processor validation. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Leaking Unsanitized GenAI Prompt and Completion Payloads Directly into Multi-Tenant Observability Backends) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

OTel