Protege datos sensibles en prompts de IA. Ofusca DNI, emails, teléfonos, IBAN y ahora también claves de API de los 16 servicios más populares antes de enviarlos a LLMs. Protect sensitive data in AI prompts. Obfuscate DNI, emails, phone numbers, IBANs and now API keys from the 16 most popular services before sending to LLMs.
Maven Central
<groupId>com.ploybot</groupId> <artifactId>prompt-shield-core</artifactId> <version>1.1.1</version>
Además de datos personales, Prompt Shield ahora detecta y ofusca automáticamente claves y tokens de 16 servicios populares —OpenAI, Anthropic, AWS, GitHub, Stripe y más— antes de que lleguen al prompt de la IA. Ideal para evitar fugas accidentales de secretos cuando un usuario pega logs, código o configuración en un chat con IA. Beyond personal data, Prompt Shield now detects and automatically obfuscates keys and tokens from 16 popular services —OpenAI, Anthropic, AWS, GitHub, Stripe and more— before they reach the AI prompt. Perfect for preventing accidental secret leaks when a user pastes logs, code or configuration into an AI chat.
Detecta y ofusca DNI, NIE, emails, teléfonos y tipos personalizados automáticamente. Detects and obfuscates DNI, NIE, emails, phone numbers and custom types automatically.
Ofusca claves de OpenAI, Anthropic, AWS, GitHub, Stripe y otros 11 servicios populares (16 en total). Obfuscates keys from OpenAI, Anthropic, AWS, GitHub, Stripe and 11 other popular services (16 total).
Los placeholders se restauran automáticamente en las respuestas de la IA. Placeholders are automatically restored in AI responses.
Inyecta un system prompt que le dice a la IA que preserve los placeholders. Injects a system prompt telling the AI to preserve placeholders.
Ofusca strings en JSON y objetos Java manteniendo la estructura. Obfuscates strings in JSON and Java objects while preserving structure.
In-Memory, Redis, JPA/H2 para almacenar tags de ofuscación. In-Memory, Redis, JPA/H2 for storing obfuscation tags.
Prefijos, separadores y tipos de datos personalizables. Customizable prefixes, separators and data types.
"Mi DNI es 12345678Z"
"Mi DNI es ~REDACTED:DNI#a1b2c3~"
La IA procesa sin ver datos reales AI processes without seeing real data
Se restauran los valores originales Original values are restored
# Input del usuario
"Mi nombre es Juan, DNI 12345678Z, email juan@email.com"
# Se envía a la IA (ofuscado)
"Mi nombre es Juan, DNI ~REDACTED:DNI#a1b2c3~, email ~REDACTED:EMAIL#d4e5f6~"
# Respuesta de la IA
"El DNI ~REDACTED:DNI#a1b2c3~ es válido. El email ~REDACTED:EMAIL#d4e5f6~ está correcto."
# Respuesta final (restaurada)
"El DNI 12345678Z es válido. El email juan@email.com está correcto."# User input
"My name is Juan, DNI 12345678Z, email juan@email.com"
# Sent to AI (obfuscated)
"My name is Juan, DNI ~REDACTED:DNI#a1b2c3~, email ~REDACTED:EMAIL#d4e5f6~"
# AI response
"The DNI ~REDACTED:DNI#a1b2c3~ is valid. The email ~REDACTED:EMAIL#d4e5f6~ is correct."
# Final response (restored)
"The DNI 12345678Z is valid. The email juan@email.com is correct."
Los modelos de IA pueden inventar, modificar o confundir datos críticos como: AI models can invent, modify or confuse critical data such as:
💡 Ejemplo: Si envías "Mi DNI es 12345678Z" sin ofuscar, la IA podría responder con "El DNI 12345678A es válido" - cambiando la letra sin que te des cuenta. 💡 Example: If you send "My DNI is 12345678Z" without obfuscation, the AI might respond with "The DNI 12345678A is valid" - changing the letter without you noticing.
Al ofuscar los datos, la IA no puede alucinar porque: By obfuscating data, the AI cannot hallucinate because:
~REDACTED:DNI#a1b2c3~, no el DNI real
Opaque placeholders: AI sees ~REDACTED:DNI#a1b2c3~, not the real DNI
💡 Con Prompt Shield: La IA recibe ~REDACTED:DNI#a1b2c3~ y responde con el mismo placeholder. Nunca toca el DNI real.
💡 With Prompt Shield: AI receives ~REDACTED:DNI#a1b2c3~ and responds with the same placeholder. It never touches the real DNI.
Procesar transferencias sin exponer IBANs Process transfers without exposing IBANs
Analizar historiales sin exponer datos médicos Analyze records without exposing medical data
Revisar contratos sin exponer datos personales Review contracts without exposing personal data
<!-- Core Library -->
<dependency>
<groupId>com.ploybot</groupId>
<artifactId>prompt-shield-core</artifactId>
<version>1.1.1</version>
</dependency>
<!-- Spring Boot Starter (optional) -->
<dependency>
<groupId>com.ploybot</groupId>
<artifactId>prompt-shield-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<!-- Spring AI Advisor (optional) -->
<dependency>
<groupId>com.ploybot</groupId>
<artifactId>prompt-shield-spring-ai-advisor</artifactId>
<version>1.1.1</version>
</dependency>
implementation 'com.ploybot:prompt-shield-core:1.1.1'
implementation 'com.ploybot:prompt-shield-spring-boot-starter:1.1.1'
implementation 'com.ploybot:prompt-shield-spring-ai-advisor:1.1.1'
import com.ploybot.promptshield.engine.ObfuscationEngine;
ObfuscationEngine engine = new ObfuscationEngine();
// Ofuscar texto
String obfuscated = engine.ofuscar("Mi DNI es 12345678Z y mi email es user@email.com");
// Resultado: "Mi DNI es ~REDACTED:DNI#1c9f96~ y mi email es ~REDACTED:EMAIL#e5a3b2~"
// Restaurar valores originales
String restored = engine.restaurar(obfuscated);
// Resultado: "Mi DNI es 12345678Z y mi email es user@email.com"
// Ofuscar string JSON
String json = "{\"dni\":\"12345678Z\",\"email\":\"user@email.com\"}";
String obfuscated = engine.ofuscarObjetoJson(json);
// Resultado: "{\"dni\":\"~REDACTED:DNI#1c9f96~\",\"email\":\"~REDACTED:EMAIL#e5a3b2~\"}"
// Restaurar JSON
String restored = engine.restaurarObjetoJson(obfuscated);
@RestController
@RequestMapping("/api/ai")
public class AiController {
private final ChatClient chatClient;
public AiController(ChatClient.Builder builder, PromptShieldAdvisor advisor) {
this.chatClient = builder
.defaultAdvisors(advisor)
.build();
}
@PostMapping("/chat")
public AiResponse chat(@RequestBody AiRequest request) {
// Los datos se ofuscan automáticamente antes de enviar a la IA
// y se restauran en la respuesta
String response = chatClient.prompt()
.user(request.message())
.call()
.content();
return new AiResponse(response);
}
}
spring:
ai:
openai:
api-key: ${OPENAI_API_KEY}
chat:
options:
model: gpt-4o-mini
prompt-shield:
enabled: true
hash-algorithm: SHA-256
hash-length: 6
storage-type: memory
redacted-prefix: "REDACTED"
tag-separator: "#"
service-keys-enabled: true # false para desactivar la detección de claves de API
custom-types:
CODIGO_POSTAL:
pattern: "\d{5}"
N_CUENTA:
pattern: "ES\d{22}"
advisor:
enabled: true
order: 0
restore-on-response: true
inject-system-prompt: true
@Service
public class MyService {
@Obfuscate
public String processPrompt(String prompt) {
// prompt se ofusca automáticamente
return aiClient.call(prompt);
}
@Obfuscate(types = {"DNI", "EMAIL"})
public String processSpecific(String prompt) {
// Solo DNI y EMAIL se ofuscan
return aiClient.call(prompt);
}
}
Por defecto. Ideal para desarrollo y testing. Default. Ideal for development and testing.
prompt-shield:
storage:
type: memory
Para producción con TTL configurable. For production with configurable TTL.
prompt-shield:
storage:
type: redis
redis:
ttl-hours: 24
Persistencia con base de datos. Database persistence.
prompt-shield:
storage:
type: jpa
jpa:
ttl-hours: 24
| Tipo Type | Patrón Pattern | Ejemplo |
|---|---|---|
| DNI | \d{8}[A-Za-z] | 12345678Z |
| NIE | [XYZxyz]\d{7}[A-Za-z] | X1234567A |
| [\w.+-]+@[\w.-]+\.\w{2,} | user@email.com | |
| TELEFONO | \d{9} | 612345678 |
| CODIGO_POSTAL | \d{5} | 28001 |
| N_CUENTA | ES\d{22} | ES1234567890123456789012 |
Prompt Shield detecta y ofusca automáticamente claves y tokens de los 16 servicios más populares antes de enviarlos a la IA, evitando fugas de secretos cuando un usuario pega código, logs o configuración en un chat. Prompt Shield automatically detects and obfuscates keys and tokens from the 16 most popular services before sending them to the AI, preventing secret leaks when a user pastes code, logs or configuration into a chat.
| Servicio Service | Tipo Type | Patrón Pattern | Ejemplo |
|---|---|---|---|
| 🤖 OpenAI | OPENAI_API_KEY | sk-proj-[A-Za-z0-9_-]{20,} | sk-proj-abc123... |
| 🧠 Anthropic | ANTHROPIC_API_KEY | sk-ant-[A-Za-z0-9_-]{20,} | sk-ant-api03-... |
| ✨ Google AI | GOOGLE_AI_KEY | AIza[A-Za-z0-9_-]{35} | AIzaSyA1b2C3d4... |
| 🤗 HuggingFace | HUGGINGFACE_TOKEN | hf_[A-Za-z0-9]{34} | hf_abc123... |
| ☁️ AWS | AWS_ACCESS_KEY | AKIA[0-9A-Z]{16} | AKIAIOSFODNN7... |
| 🔷 Azure | AZURE_STORAGE_KEY | [A-Za-z0-9+/]{88}== | AbCdEf...== |
| 🌊 DigitalOcean | DIGITALOCEAN_TOKEN | dop_v1_[a-f0-9]{64} | dop_v1_abc... |
| 🐙 GitHub | GITHUB_TOKEN | gh[psoa]_[A-Za-z0-9]{36} | ghp_abc123... |
| 🦊 GitLab | GITLAB_TOKEN | glpat-[A-Za-z0-9_-]{20,} | glpat-abc123... |
| 📦 NPM | NPM_TOKEN | npm_[A-Za-z0-9]{36} | npm_abc123... |
| 🐍 PyPI | PYPI_TOKEN | pypi-[A-Za-z0-9_-]{60,} | pypi-AgEIcHl... |
| 💬 Slack | SLACK_TOKEN | xox[bpsa]-[0-9]{10,13}-[a-zA-Z0-9-]{20,} | xoxb-123456789012-... |
| 📞 Twilio | TWILIO_API_KEY | SK[0-9a-fA-F]{32} | SKabcdef0123... |
| 📧 SendGrid | SENDGRID_KEY | SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43} | SG.abc123...XYZ |
| ✉️ Mailgun | MAILGUN_API_KEY | key-[0-9a-zA-Z]{32} | key-abcdef0123... |
| 💳 Stripe | STRIPE_KEY | (?:sk|pk|rk)_(?:live|test)_[0-9a-zA-Z]{24,} | sk_live_abc123... |
💡 Los service keys se pueden desactivar con service-keys-enabled: false en la configuración.
💡 Service keys can be disabled with service-keys-enabled: false in the configuration.
Empieza a usar Prompt Shield hoy y protege los datos sensibles de tus usuarios. Start using Prompt Shield today and protect your users' sensitive data.