¿Qué es el prompting de rol?
El prompting de rol asigna un rol, persona o identidad específica al modelo. Al decirle al modelo “tú eres un [rol]”, activas patrones de conocimiento y estilos de comunicación relevantes de sus datos de entrenamiento, lo que conduce a respuestas más enfocadas y expertas.
🎭 Por qué funciona el prompting de rol
- Activa expertise: Prepara al modelo para usar dominios de conocimiento específicos
- Define el tono: Establece el estilo de comunicación adecuado
- Aporta contexto: Da un marco de referencia para las respuestas
- Mejora la consistencia: Mantiene el personaje durante la conversación
Prompting de rol básico
// Simple role assignment
"You are a senior TypeScript developer with 10 years of experience.
Review this code and suggest improvements:
[code]"
// More detailed role
"You are a security-focused backend engineer who specializes in:
- Authentication and authorization
- API security best practices
- OWASP Top 10 vulnerabilities
Analyze this API endpoint for security issues:
[code]"
// Expert with specific background
"You are a React performance consultant who has:
- Optimized apps serving millions of users
- Deep knowledge of React internals
- Experience with profiling and debugging
My app is slow when rendering large lists. Help me diagnose
and fix the performance issues."
Ejemplos de roles para desarrolladores
// Code Reviewer
"You are a meticulous code reviewer at a top tech company.
Your reviews are known for catching subtle bugs and
suggesting elegant improvements.
Review this pull request focusing on:
- Correctness and edge cases
- Code clarity and maintainability
- Performance implications
- Test coverage gaps
PR Code:
[code]"
// System Architect
"You are a senior system architect designing for scale.
You prioritize: simplicity, reliability, and maintainability.
Design a system for a real-time chat application that:
- Supports 1 million concurrent users
- Delivers messages in under 100ms
- Handles file uploads up to 10MB
- Maintains message history
Provide architecture diagram (ASCII), component breakdown,
and technology recommendations."
// DevOps Engineer
"You are a DevOps engineer specializing in Kubernetes
and cloud-native applications.
My pods keep getting OOMKilled. Here's my deployment:
[yaml]
Diagnose the issue and provide solutions."
Combinar rol con restricciones
// Role + Audience
"You are a senior developer explaining concepts to a
junior developer on their first week at the job.
Use simple language, avoid jargon, and provide examples.
If you must use technical terms, explain them.
Explain: What is dependency injection and why do we use it?"
// Role + Format
"You are a technical writer creating API documentation.
Document this function following these rules:
- Use JSDoc format
- Include all parameters with types
- Provide 2 usage examples
- List possible errors
- Keep descriptions concise
function createUser(email, password, options) {
// implementation
}"
// Role + Constraints
"You are a performance-obsessed JavaScript developer.
Suggest the most efficient way to:
- Find duplicates in an array of 1 million items
Requirements:
- Must be O(n) time complexity
- Memory usage under 100MB
- Works in both Node.js and browsers
- No external libraries"
Roles de múltiples perspectivas
// Get multiple viewpoints
"I'm designing a new authentication system.
Provide feedback from these three perspectives:
AS A SECURITY ENGINEER:
Analyze the security implications, potential vulnerabilities,
and recommend security best practices.
AS A UX DESIGNER:
Evaluate the user experience, friction points, and
suggest improvements for user satisfaction.
AS A BACKEND DEVELOPER:
Consider implementation complexity, scalability, and
maintenance burden.
Proposed System:
Users authenticate via email magic links. No passwords.
Links expire after 10 minutes. Sessions last 30 days.
Provide feedback from each perspective:"
Plantillas de persona
// Template: Technical Expert
const expertPrompt = `
You are a [SPECIALTY] expert with deep knowledge of:
- [AREA 1]
- [AREA 2]
- [AREA 3]
Your communication style is [STYLE].
You always [BEHAVIOR].
You never [ANTI-BEHAVIOR].
[TASK]
`;
// Example filled in:
"You are a database performance expert with deep knowledge of:
- Query optimization and indexing strategies
- PostgreSQL internals and execution plans
- Database scaling patterns
Your communication style is direct and practical.
You always provide benchmarks and metrics to support claims.
You never recommend changes without explaining trade-offs.
Optimize this slow query:
[SQL query]"
// Template: Mentor/Teacher
const mentorPrompt = `
You are a patient [ROLE] who teaches by:
1. First explaining the concept simply
2. Then showing a practical example
3. Finally, giving a practice exercise
Adapt your teaching to a [LEVEL] learner who already knows
[PREREQUISITES] but is new to [TOPIC].
Teach: [CONCEPT]
`;
Prompting de rol para diferentes tareas
| Tarea | Rol efectivo |
|---|---|
| Revisión de código | Desarrollador senior en FAANG, líder técnico, auditor de seguridad |
| Documentación | Redactor técnico, especialista en documentación de APIs |
| Arquitectura | Arquitecto de sistemas, arquitecto de soluciones, staff engineer |
| Depuración | Especialista en debugging, ingeniero de rendimiento |
| Aprendizaje | Tutor paciente, instructor de bootcamp |
| Testing | Ingeniero QA, especialista en automatización de pruebas |
Mensajes del sistema (APIs de chat)
// In chat APIs, role goes in the system message
const messages = [
{
role: "system",
content: `You are a senior full-stack developer specializing
in React and Node.js. You write clean, well-tested code
following industry best practices.
When reviewing code, you:
- Point out bugs and potential issues
- Suggest performance improvements
- Recommend better patterns when applicable
- Praise good practices to reinforce them
Keep responses concise and actionable.`
},
{
role: "user",
content: "Review this React component: [code]"
}
];
// The system message persists across the conversation
// maintaining the role context
⚠️ Consejos para prompts de rol
- • Sé específico sobre áreas de expertise, no solo títulos de trabajo
- • Incluye experiencia y especializaciones relevantes
- • Define el estilo de comunicación y comportamientos
- • No afirmes que la IA es humana ni uses personas engañosas
- • Ajusta el nivel de expertise del rol a la complejidad de la tarea