Use this prompt when you have a valid OpenAPI 3.0 or 3.1 specification and a defined PII taxonomy, and you need to produce a compliance-ready spec where every schema property containing personally identifiable information is annotated with x-pii extension properties. The ideal user is a privacy engineer, security reviewer, or API governance team member who must prepare an API specification for downstream consumption by data catalogs, audit systems, or automated compliance tooling. The prompt applies your classification rules to the schema surface—it does not create the taxonomy itself or make legal determinations about data classification.
Prompt
OpenAPI Spec PII Data Field Annotation Prompt Template

When to Use This Prompt
Identify when to apply systematic PII annotation to an OpenAPI spec and when a different approach is required.
This prompt is appropriate when the work is schema-structural: you need to walk every property in every schema, compare it against a known list of PII categories (such as email, phone, ssn, ip_address, name, location), and emit annotations that include the data category, retention policy, encryption requirement, and any masking or access-control notes. The output is a modified OpenAPI spec with x-pii objects attached to the relevant properties. This is a compliance engineering task, not a legal review task. The prompt assumes the taxonomy and classification rules are already decided and provided as input.
Do not use this prompt when you need to create a PII taxonomy from scratch, when you need to make legal judgments about whether a field constitutes PII under a specific regulation, or when the spec is malformed and cannot be parsed. Do not use it for runtime data scanning or dynamic data classification—this prompt operates on the static API contract, not on live payloads. If your OpenAPI spec uses heavy $ref indirection, oneOf/anyOf polymorphism, or external schema registries, you should resolve references before running this prompt or provide a resolved version as input. The prompt works best on flattened, dereferenced schemas where every property is directly inspectable. After running the prompt, always validate the output spec with an OpenAPI validator and review a sample of annotations manually before committing the result to a compliance pipeline.
Use Case Fit
Where the PII annotation prompt delivers reliable results and where it introduces unacceptable risk. Match the workflow to the prompt's strengths.
Good Fit: Structured Schema Annotation
Use when: you have a complete OpenAPI spec and need to systematically flag properties that contain PII. The prompt excels at identifying common PII patterns (email, SSN, phone, address) and adding consistent x-pii extension properties. Guardrail: Always provide a concrete taxonomy of PII categories, retention rules, and encryption requirements as part of [CONSTRAINTS] to prevent inconsistent labeling.
Bad Fit: Ambiguous or Context-Dependent PII
Avoid when: PII classification depends on business context the model cannot see, such as combined fields that become identifying only when joined, or fields whose sensitivity varies by jurisdiction. The model cannot reliably determine that pet_name plus zip_code constitutes PII in your specific regulatory environment. Guardrail: Route ambiguous schemas to a human privacy reviewer. Use the prompt only for clear-cut PII patterns.
Required Input: PII Taxonomy and Policy Rules
Risk: Without a defined taxonomy, the model invents categories, misses regulated data types, or applies inconsistent retention labels. Guardrail: Provide a structured [PII_TAXONOMY] input with explicit categories (e.g., direct_identifier, sensitive_attribute, financial_account), plus [RETENTION_RULES] and [ENCRYPTION_REQUIREMENTS] as part of the prompt harness. The output schema must reference only categories you define.
Operational Risk: Spec Drift After Annotation
Risk: The annotated spec becomes stale when the API evolves. New endpoints or schema changes may introduce unmarked PII fields. Guardrail: Integrate the annotation prompt into your CI pipeline so it runs on every spec change. Pair it with a breaking-change detector that flags when previously annotated fields are modified or removed. Never treat a one-time annotation pass as complete.
Bad Fit: Regulatory Compliance Certification
Risk: Teams may treat model-generated x-pii annotations as evidence of GDPR, HIPAA, or PCI compliance. The model cannot certify compliance and may miss regulated data categories specific to your industry. Guardrail: Use this prompt only as a first-pass detection tool. Every annotation must be reviewed by a qualified privacy engineer or DPO before the spec is used for compliance evidence. Document the review step in your governance log.
Good Fit: Multi-Service PII Inventory
Risk: Organizations with dozens of microservices lose track of which services handle PII. Manual audits are slow and inconsistent. Guardrail: Run this prompt across all service specs with a consistent taxonomy. Aggregate results into a PII inventory dashboard that maps every flagged field to its service, endpoint, and data category. This turns the prompt into a scalable discovery tool rather than a one-off annotation helper.
Copy-Ready Prompt Template
A copy-pasteable prompt template for annotating PII data fields in an OpenAPI specification with privacy metadata.
This prompt template instructs the model to scan a provided OpenAPI specification, identify every schema property that contains personally identifiable information (PII), and annotate those fields with x-pii extension properties. The template is designed to be dropped into your AI harness, with square-bracket placeholders that you must replace with your organization's specific data categories, retention policies, and encryption standards before execution. The output is a modified OpenAPI spec, not a separate report, ensuring that privacy metadata lives directly alongside the data definitions that downstream tools and code generators consume.
markdownYou are a privacy engineering assistant. Your task is to analyze the provided OpenAPI specification and annotate every schema property that contains Personally Identifiable Information (PII). ## Input [OPENAPI_SPEC] ## PII Taxonomy Use the following data categories to classify each PII field. A field may have multiple categories. [PII_CATEGORIES] ## Annotation Rules For every property you identify as PII, add an `x-pii` object with the following required fields: - `category`: An array of strings from the provided taxonomy. - `retention_policy`: A string referencing the applicable policy from [RETENTION_POLICIES]. - `encryption_required`: A boolean indicating if the field must be encrypted at rest based on [ENCRYPTION_POLICY]. - `masking_strategy`: A string indicating how the field should be masked in logs, such as "FULL", "PARTIAL_LAST_FOUR", or "NONE". ## Constraints - Do not modify any existing schema structure, types, or descriptions. - Do not annotate fields that are clearly non-PII, such as generic IDs, timestamps, or status enums, unless specified in [EXCEPTIONS]. - If a field's PII status is ambiguous, flag it with `"review_required": true` and provide a brief `"review_note"`. - Return the complete, modified OpenAPI specification as a valid JSON or YAML object matching the input format. ## Output Schema Return only the modified OpenAPI specification. Do not include any explanatory text outside the spec.
To adapt this template, replace [PII_CATEGORIES] with your internal data classification taxonomy, such as ["PII", "SPI", "PHI", "FINANCIAL"]. Replace [RETENTION_POLICIES] with a list of your organization's approved retention policy names, and [ENCRYPTION_POLICY] with the rule that determines when encryption is mandatory (e.g., "all SPI and PHI fields"). The [EXCEPTIONS] placeholder should list any fields that are normally non-PII but must be treated as sensitive in your context, such as internal user IDs. Before running this prompt in production, validate the output with a schema conformance check against the original spec and a human review step for any field flagged with review_required: true.
Prompt Variables
Each placeholder required by the OpenAPI Spec PII Data Field Annotation Prompt Template. Use these to construct the prompt payload and validate inputs before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[OPENAPI_SPEC] | The raw OpenAPI specification (JSON or YAML) containing schemas to scan for PII fields. | openapi: 3.1.0 components: schemas: User: properties: email: type: string | Must parse as valid OpenAPI 3.0 or 3.1. Reject if spec fails structural validation against the OpenAPI schema. YAML must be converted to JSON before schema conformance check. |
[PII_CATEGORIES] | A list of PII categories to detect, mapping to standard data classification taxonomies. | ["direct_identifier", "indirect_identifier", "sensitive_personal", "financial", "biometric", "government_id"] | Must be a non-empty array of strings. Validate against an allowed category enum. Unknown categories should trigger a warning before prompt execution. |
[RETENTION_RULES] | A mapping of PII categories to retention policies required by the organization's data governance framework. | {"direct_identifier": "delete_after_90_days", "financial": "retain_7_years", "default": "retain_30_days"} | Must include a 'default' key. Each value must match an allowed retention action enum. Null allowed if retention annotation is out of scope for this run. |
[ENCRYPTION_STANDARDS] | A mapping of data-at-rest and data-in-transit encryption requirements per sensitivity level. | {"sensitive_personal": "aes-256-gcm", "financial": "aes-256-gcm", "default": "tls-1.3-transit-only"} | Must include a 'default' key. Encryption values must reference approved standards from the organization's security policy. Reject unknown encryption strings. |
[OUTPUT_SCHEMA] | The expected JSON schema for the annotated output, defining the structure of x-pii extension properties. | {"type": "object", "properties": {"x-pii": {"type": "object", "properties": {"category": {"type": "string"}, "retention_policy": {"type": "string"}, "encryption_required": {"type": "string"}, "masking_strategy": {"type": "string"}}, "required": ["category"]}}} | Must be a valid JSON Schema. The schema must define x-pii as an object with at least a required 'category' field. Validate with a JSON Schema validator before passing to the model. |
[SCHEMA_PATHS] | An optional array of JSON Pointers to specific schema objects to annotate. If omitted, all component schemas are scanned. | ["#/components/schemas/User", "#/components/schemas/PaymentMethod"] | If provided, each pointer must resolve to an existing schema object in [OPENAPI_SPEC]. Null or empty array means scan all schemas. Validate pointer resolution before prompt execution. |
[MASKING_STRATEGIES] | A mapping of PII categories to recommended masking or pseudonymization strategies for logging and non-production environments. | {"direct_identifier": "redact", "indirect_identifier": "hash", "financial": "tokenize", "default": "none"} | Must include a 'default' key. Allowed values: redact, hash, tokenize, partial_mask, none. Reject unknown strategies. |
Implementation Harness Notes
How to wire the PII annotation prompt into a privacy review pipeline with validation, retries, and human approval gates.
The PII annotation prompt is designed to operate as a batch processing step within a CI/CD pipeline or a privacy review workflow. You feed it one or more OpenAPI schema objects, and it returns annotated schemas with x-pii extension properties. The harness should treat this as a deterministic enrichment task, not a conversational interaction. Each schema object should be processed independently to limit blast radius and simplify retry logic. The prompt expects a JSON-serializable schema fragment as [INPUT], an optional [PII_CATEGORIES] list to constrain detection scope, and a [RETENTION_POLICY] string to apply as default guidance. The output is a modified schema with x-pii blocks injected into property definitions that the model flags as containing personally identifiable information.
Validation and retry logic is critical because missing a PII field is a compliance risk, while over-flagging creates noise. After the model returns an annotated schema, run a structural validator that checks: (1) every x-pii block contains the required keys category, retention, encryption_required, and rationale; (2) no x-pii block appears on a property that was not in the input schema; (3) the output schema is valid JSON and structurally identical to the input aside from the added extensions. If validation fails, retry once with the error message appended to [CONSTRAINTS]. If the retry also fails, route the schema to a human review queue rather than silently accepting a malformed output. For high-sensitivity APIs, consider requiring human approval on all newly flagged fields before merging.
Model choice and tool use matter here. This task benefits from models with strong schema comprehension and low hallucination rates on structured data. Avoid models that tend to rewrite or reorder schema properties. Do not provide the model with tools that could modify the schema beyond annotation—this is a read-and-enrich task, not a schema generation task. If your pipeline processes large specs, split the spec into individual schema components before invoking the prompt, and run annotations in parallel with a concurrency limit to avoid rate limiting. Log every annotation decision with the model version, input hash, and output hash for auditability. The next step after successful annotation is typically merging the enriched schemas back into the source OpenAPI file and running a downstream Spectral ruleset that verifies every property with a known PII data type carries an x-pii annotation.
Expected Output Contract
The exact structure, fields, and validation rules for the model response when annotating PII data fields in an OpenAPI specification.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
annotated_spec | object | Must be a valid OpenAPI 3.0 or 3.1 JSON object. Parse check with an OpenAPI schema validator must pass. | |
annotated_spec.components.schemas..properties..x-pii | object | If present, must contain data_category, retention_policy, and encryption_required fields. Schema check for required sub-fields. | |
annotated_spec.components.schemas..properties..x-pii.data_category | string | true (if x-pii exists) | Must be one of the approved enum values: [PII, PHI, PCI, credentials, location, behavioral, other]. Enum check against the defined list. |
annotated_spec.components.schemas..properties..x-pii.retention_policy | string | true (if x-pii exists) | Must be a non-empty string describing the retention period or policy. Null check and length > 0. |
annotated_spec.components.schemas..properties..x-pii.encryption_required | boolean | true (if x-pii exists) | Must be a boolean value. Type check for true or false. |
annotated_spec.components.schemas..properties..x-pii.notes | string | If present, must be a string. Null allowed. No further validation required. | |
pii_field_summary | object | Must contain total_fields_analyzed, pii_fields_found, and pii_fields_flagged arrays. Schema check for all three keys. | |
pii_field_summary.pii_fields_flagged | array | Each item must be a JSON pointer string (e.g., #/components/schemas/User/properties/email) that resolves to a property with an x-pii extension in the annotated_spec. Citation check against the annotated_spec. |
Common Failure Modes
What breaks first when using LLMs to annotate PII in OpenAPI specs, and how to prevent it before it reaches production.
False Negatives on Non-Obvious PII
What to watch: The model misses indirect identifiers like IP addresses, device fingerprints, session tokens, or composite fields that together identify a person. It flags obvious fields like email but skips client_ip, user_agent, or correlation_id when combined with timestamps. Guardrail: Provide a comprehensive taxonomy of PII categories in the prompt, including network identifiers, pseudonymous IDs, and behavioral signals. Add a post-processing check that flags any string or numeric field without an x-pii annotation for human review.
Inconsistent x-pii Extension Schema
What to watch: The model invents its own x-pii structure across different runs or different parts of the spec. One field gets x-pii: true, another gets x-pii: {category: "email"}, and a third gets x-pii: {type: "PII", level: "high"}. Downstream tooling breaks on the inconsistency. Guardrail: Include the exact x-pii schema in the prompt as a required output contract. Validate every annotated property against that schema immediately after generation. Reject or repair any property that doesn't conform.
Context Window Truncation on Large Specs
What to watch: When the OpenAPI spec exceeds the model's context window, the model silently drops trailing paths or component schemas. PII fields in the truncated portion receive no annotation at all, creating a false sense of coverage. Guardrail: Chunk the spec by path or schema component before processing. Track which chunks were submitted and which received annotations. Reconcile the annotated output against the original spec to detect missing sections. Flag any path or schema present in the input but absent from the annotated output.
Over-Annotation of Non-PII Fields
What to watch: The model flags fields like product_id, order_number, or department_code as PII because they contain alphanumeric strings or look like identifiers. This causes unnecessary encryption, retention restrictions, and access controls on business data. Guardrail: Include negative examples in the prompt showing common non-PII identifiers that should not be flagged. Add a human review step for any field annotated as PII that doesn't match a known category from your data classification policy.
Retention and Encryption Policy Hallucination
What to watch: The model generates plausible-sounding but incorrect values for x-pii.retention_policy or x-pii.encryption_required that don't match your organization's actual data governance rules. A field might get retention: "30 days" when your policy requires 90 days, or encryption_required: false when the data is classified as sensitive. Guardrail: Supply the exact allowed values for retention policies, encryption requirements, and data categories in the prompt. Validate every generated value against an allowlist. Route any value not on the allowlist to a human reviewer before the spec is published.
Nested and Referenced Schema Blind Spots
What to watch: The model annotates top-level properties but misses PII inside nested objects, arrays of objects, or $ref-referenced schemas. A shipping_address object might be flagged, but recipient_phone inside it is skipped. AllOf/oneOf/anyOf compositions are especially prone to incomplete traversal. Guardrail: Instruct the model to recursively traverse all nested schemas and resolve $ref targets before annotating. After generation, walk the entire resolved spec programmatically and flag any leaf property with a PII-like name (phone, email, ssn, dob, address, ip, token) that lacks an x-pii annotation.
Evaluation Rubric
Criteria for evaluating the quality of PII annotation output before integrating this prompt into a production API governance pipeline.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
PII Field Coverage | Every property containing direct or indirect identifiers is annotated with an x-pii extension | A known PII field such as email, phone, or SSN is present in the spec but missing the x-pii object | Schema-aware diff against a manually verified golden spec for the same API surface |
Data Category Accuracy | Each x-pii.dataCategory value matches the actual data type from the allowed enum: direct-identifier, indirect-identifier, sensitive, financial, health, credential | A field containing a credit card number is categorized as direct-identifier instead of financial | Automated check that every dataCategory value is a member of the allowed enum and spot-check 20% of assignments against a human-labeled set |
Retention Policy Assignment | Every annotated field includes a non-empty x-pii.retentionPolicy string that references a real policy name or duration | A PII-annotated field has null, empty string, or placeholder text such as TBD in the retentionPolicy field | Regex validation for non-empty string and grep for banned placeholder tokens across the output spec |
Encryption Requirement Flag | Every annotated field includes x-pii.encryptionRequired as a boolean and fields categorized as sensitive, financial, health, or credential are set to true | A health data field has encryptionRequired set to false or the property is missing entirely | Schema validation requiring the boolean field and a rule engine check that encryptionRequired is true for all high-sensitivity categories |
Extension Schema Validity | All x-pii extension objects conform to the defined schema with required fields present and no additional unknown properties | An x-pii object contains a misspelled key such as dataCatagory or includes an undefined property | JSON Schema validation of every x-pii object against the extension schema definition |
Non-PII Field Non-Interference | Properties that do not contain PII have no x-pii extension and their existing schema annotations remain unchanged | A non-PII field such as a product SKU or public timestamp receives an x-pii annotation or its description field is altered | Diff the non-PII properties between input and output spec and flag any added x-pii objects or modified existing fields |
Downstream Tool Compatibility | The annotated spec passes validation with common OpenAPI tooling and parsers without errors or warnings | Spectral linter or OpenAPI validator throws errors due to malformed extension placement or invalid spec structure | Run the output spec through a standard OpenAPI 3.0/3.1 validator and a Spectral ruleset that allows x-pii extensions |
Handling of Nested and Array Properties | PII fields inside nested objects and arrays of objects are annotated at the property level, not just the parent | An address object contains a zip code PII field but only the parent address property receives the x-pii annotation | Recursive walk of all nested schemas and array item schemas to verify that every leaf property with PII has its own x-pii object |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Use the base prompt with a single schema file and lighter validation. Replace [PII_CATEGORIES] with a short list of high-priority data types (email, phone, SSN). Skip retention policy and encryption requirement fields initially. Run against one endpoint's schema before scaling.
Prompt modification
Remove or comment out the [RETENTION_POLICY] and [ENCRYPTION_REQUIREMENT] fields from [OUTPUT_SCHEMA]. Add: If uncertain whether a field contains PII, flag it with x-pii-category: "needs_review".
Watch for
- Missing nested PII inside arrays and objects
- Overly broad flags on fields like
idornamewithout context - No distinction between direct identifiers and quasi-identifiers

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us