13 min read
Lesson 4 of 5
Secure AI Development Practices
From the course Prompt Injection & AI Security
Building secure AI applications requires security thinking throughout the development lifecycle, not just at deployment.
Secure Development Lifecycle for AI
Design phase:
- Threat modeling: Identify what an attacker could gain and how they might try
- Minimal authority: Design the system with the least privilege necessary
- Human oversight: Plan where human approval is required
- Fail-safe defaults: When in doubt, refuse rather than comply
Implementation phase:
- Never put secrets in system prompts (the model can leak them)
- Sanitize all inputs before passing to the LLM
- Validate all outputs before acting on them
- Log all interactions for audit and incident response
- Implement rate limiting and abuse detection
Testing phase:
- Automated adversarial testing with known attack datasets
- Manual red teaming by security-minded team members
- Boundary testing: push every feature to its limits
- Test with real user data patterns (anonymized)
Deployment phase:
- Monitor for novel attack patterns
- Alert on unusual behavior (high refusal rates, unusual topics)
- Have incident response procedures ready
- Plan for rapid model/prompt updates when vulnerabilities are found
Secure Tool Integration
When your LLM calls external tools:
# BAD: LLM directly constructs SQL
query = llm.generate(f"Write SQL for: {user_request}")
db.execute(query) # SQL injection risk!
# GOOD: LLM selects from predefined actions
action = llm.select_action(user_request, allowed_actions=[
"get_order_status",
"list_products",
"update_preferences",
])
result = execute_action(action, validated_params)
Supply Chain Security
- Verify model sources (download only from official repositories)
- Pin model versions (don't auto-update in production)
- Audit third-party prompts and templates
- Review plugin/extension permissions before integration
- Monitor for model poisoning attacks on fine-tuning data
Incident Response for AI
When a security incident occurs:
- Contain: Disable the affected feature or endpoint immediately
- Assess: Determine what data was exposed or what harm occurred
- Investigate: Review logs to understand the attack vector
- Remediate: Patch the vulnerability (update prompts, add filters, restrict access)
- Communicate: Notify affected users and stakeholders as required
- Learn: Update threat models and security tests to prevent recurrence
Key Takeaways
- •Never put secrets in system prompts — assume the model can leak any information it has access to
- •Use predefined action selection instead of letting the LLM construct queries or commands directly
- •Pin model versions, verify sources, and audit third-party prompts for supply chain security
- •Have an AI incident response plan: contain, assess, investigate, remediate, communicate, learn
0 of 5 lessons marked complete
Progress is kept in this browser only.