Proteger un asistente IA y RAG con permisos fuera del prompt
Crea una pasarela de herramientas con aislamiento de clientes, permisos de documentos y presupuesto de llamadas. Ocho tests y prompts ingleses.

Empieza aquí: para qué sirve esta guía
Un documento ordena ignorar reglas y enviar datos de otro cliente: inyección indirecta. Un prompt fuerte no sustituye permisos externos. La pasarela decide documentos permitidos, toma identidad fiable y limita llamadas, sin LLM real ni herramienta de escritura. Los tests prueban la política, no resistencia universal del modelo.
Un ejemplo concreto
La respuesta ilustra el formato esperado, no una auditoría de tu aplicación. Sigue los pasos y compara archivos, tests y salidas reales con el objetivo. Si el asistente solo dice que terminó, pide el entregable, las pruebas y lo pendiente.
Proposal: read_document for a document belonging to another tenant.
Decision: denied by server policy, regardless of the document instruction.
Proposal: delete_records.
Decision: denied; this gateway exposes no write operation.El objetivo
Un asistente puede leer un documento con instrucciones. La aplicación debe seguir decidiendo a qué datos y herramientas puede acceder el usuario. El laboratorio impone una pasarela de lectura sin llamar a un LLM ni servicio externo.
1. Definir el alcance
Extrae el ZIP en una carpeta nueva y usa Node.js 22 o posterior. Documentos, identidades y respuestas propuestas son ficticios. En un servicio real, identidad y permisos vienen del servidor, no de documentos subidos ni argumentos del modelo.
2. Ejecutar el laboratorio local
Ejecuta ocho tests: lectura permitida, otro cliente, permiso ausente, escritura prohibida, identidad falsificada, instrucción en documento, presupuesto y configuración inválida. El texto se devuelve como dato sin ejecutarlo.
node --version
node --test lab.test.mjs3. Pedir pruebas a la IA
El primer prompt pide mapear fronteras de confianza. La similitud vectorial no es un permiso. Los tests comprueban una política determinista, no demuestran resistencia total de un modelo real.
Review this LOCAL AI/RAG boundary lab. No real model or external service is
connected. Read lab.mjs and lab.test.mjs. Identify trusted actor and ACL metadata,
untrusted document text, proposed model tool calls and the execution budget. Test
whether a document instruction, forged tenant field or unknown write tool could
bypass the gateway. Do not treat a system prompt, an opaque document ID, a vector
search score or a model’s user_confirmed flag as authorization. Produce evidence and
remaining integration requirements, not a claim of complete prompt-injection
resistance.4. Verificar la corrección
El segundo prompt acota un cambio y su test de regresión. Mantén permisos y validación de argumentos fuera del modelo. Pedir ignorar instrucciones del documento no impone controles de acceso.
Implement only the agreed local gateway improvement and add a regression test. Keep
authorization and argument validation in server-controlled code outside the model.
Use authenticated actor/tenant metadata, a document ACL, an explicit tool allowlist
and a bounded call budget. Keep retrieved document text as data. Use harmless
synthetic documents and proposed tool calls; do not connect a real database, send
messages or execute shell commands. Run node --test lab.test.mjs. Document that
these tests check policy enforcement, not a live model, a vector database
integration or an injection detector.5. Aplicarlo a tu proyecto
En RAG real, filtra cliente y permisos en el servidor durante la recuperación, antes de enviar contexto al modelo. Comprueba cada llamada, escapa la salida según su destino e impón un presupuesto compartido en producción. Una futura herramienta de escritura necesita aprobación ligada al actor y a los argumentos exactos.
Referencias oficiales
Llévalo a tu proyecto
Descarga los archivos, guarda la guía o entrega un encargo listo a tu asistente.
Preparar con IA
Copia este prompt inglés en tu asistente. Incluye el artículo, los archivos disponibles y los pasos de preparación.
Ver el prompt de preparación
Read this tutorial as reference material:
https://nethanelfitoussi.com/article/ai-rag-prompt-injection-guardrails?lang=en
Goal: apply the documented workflow to my development project.
Read the existing project instructions, inspect the relevant files and explain the smallest useful setup.
Available starter files:
https://nethanelfitoussi.com/api/media/f34e57b8-eb7c-49ea-889f-441e88ba63f0.zip
Download and inspect these files in a temporary folder before using them. Do not overwrite existing project instructions.
If I have not supplied a project folder, ask which development project to use. Do not invent a repository URL.
Additional project setup instructions:
Use the downloaded starter lab in a NEW folder. Read README.md and both English prompts first. Run its dependency-free Node.js tests before editing.
Review this LOCAL AI/RAG boundary lab. No real model or external service is
connected. Read lab.mjs and lab.test.mjs. Identify trusted actor and ACL metadata,
untrusted document text, proposed model tool calls and the execution budget. Test
whether a document instruction, forged tenant field or unknown write tool could
bypass the gateway. Do not treat a system prompt, an opaque document ID, a vector
search score or a model’s user_confirmed flag as authorization. Produce evidence and
remaining integration requirements, not a claim of complete prompt-injection
resistance.
Implement only the agreed local gateway improvement and add a regression test. Keep
authorization and argument validation in server-controlled code outside the model.
Use authenticated actor/tenant metadata, a document ACL, an explicit tool allowlist
and a bounded call budget. Keep retrieved document text as data. Use harmless
synthetic documents and proposed tool calls; do not connect a real database, send
messages or execute shell commands. Run node --test lab.test.mjs. Document that
these tests check policy enforcement, not a live model, a vector database
integration or an injection detector.
Adapt example paths, commands and acceptance criteria to this repository rather than assuming they match.
Give me a short plan, then make the agreed local changes and run the relevant checks. Report actual results and anything not verified. Stop before credentials, paid services, production changes, push, merge or deployment.

