TL;DR: Prompts are too generic to be useful. This post covers two frameworks (RCTF and Chain-of-Thought), a side-by-side bad vs good comparison using SQL injection and AWS privilege escalation, and a prompt optimizer shortcut for when you're under time pressure

Introduction

AI tools are only as good as the prompts you give them

Security engineers are using LLMs for code review, incident triage, threat modeling, and detection writing. But most prompts are vague. The output ends up generic, textbook-level, and not actionable

A good prompt changes that by giving the AI enough context to think like a security engineer. It scopes the task. It defines what a useful answer looks like

Prerequisites

  • Access to Claude, GPT-4, or any capable LLM

  • A security task in mind (code review, IR, detection writing)

  • No prompt engineering experience required

Why Security Prompts Are Different

Security tasks are high-stakes. A wrong answer can mislead a triage decision. A vague remediation suggestion can introduce new issue

The AI has no idea what stack you're running

  • It doesn't know if you're on AWS or on-prem

  • It doesn't know your severity thresholds, Without that context, it gives you a generic answer

LLMs need to be told how to think. They need a role, a technical environment, a scoped task, and a defined output. Without those inputs, you get a Wikipedia summary.

Good Prompt vs Bad Prompt - See the Difference First

Before any framework, look at real examples

SQL Injection Vulnerability Review

Bad prompt:

"Review my code for SQL injection."

What you get: A generic explanation of SQL injection. Maybe a mention of parameterized queries. Nothing specific to your code or stack.

Prompt: Send the below prompt to Claude

You are a senior application security engineer specializing in OWASP Top 10

I have a Python Flask app using raw psycopg2 with a PostgreSQL database
The /login endpoint concatenates username directly into a SQL string from a POST request body

Review the code below.
Identify the vulnerable line, explain the attack vector, provide a fixed version using parameterized queries, and estimate a CVSS v3.1 score

Return results as:

1) Vulnerable line
2) Attack example
3) Fixed code
4) CVSS score

What you get: A line-by-line review, a working exploit string, corrected code with %s placeholders, and a reasoned CVSS score. Immediately actionable.

Incident Response - AWS Privilege Escalation

Bad prompt:

"Help me investigate an AWS incident."

What you get: A list of general IR steps. Check CloudTrail. Look for unusual API calls. Nothing you don't already know.

Prompt: Send the below prompt to Claude

You are a cloud incident responder specializing in AWS IAM forensics.

An EC2 instance with role arn:aws:iam::123456789012:role/dev-ec2-role
made 47 AssumeRole calls to
arn:aws:iam::123456789012:role/prod-admin-role
within 3 minutes at 02:14 UTC

CloudTrail shows s3:GetObject calls to prod-data-bucket
immediately after

Determine if this is a privilege escalation

Return:
1) Attack classification
2) Blast radius
3) Containment steps ordered by priority
4) Evidence to preserve before remediation

What you get: A classification (likely MITRE T1548.005), a blast radius scoped to the specific role and bucket, ordered containment actions, and a forensic evidence checklist. Ready to hand off to your team.

What Makes the Difference

Five mistakes separate the bad prompt from the good:

  1. Vague role - "act as a security expert" tells the AI nothing. Name the specialization.

  2. No environment context - which cloud, which language, which framework. Missing context = generic output.

  3. No scope or severity constraint - the AI doesn't know if you want a quick triage or a deep review.

  4. Everything in one prompt - asking to detect, explain, fix, and document in one ask without structure.

  5. No output format - without a format, the AI decides. It usually picks prose. You usually want a structured list.

Framework #1 - RCTF (Role, Context, Task, Format)

RCTF is a four-part structure. Each part removes ambiguity. Together, they produce a prompt that behaves like a well-briefed analyst

  • R - Role: Define who the AI is. Be specific about the domain

  • C - Context: Describe the technical environment. Stack, tool, version, what happened

  • T - Task: State exactly what to do. One scoped action, not five open-ended ones

  • F - Format: Tell the AI how to return the answer.

Example 1 - SQL Injection Vulnerability Review

Role: You are a senior appsec engineer with expertise in Python web security and OWASP Top 10.

Context: The app is a Python Flask API using raw psycopg2 to query a PostgreSQL database.
The /login endpoint accepts username and password as JSON. The query is built
by string concatenation: query = "SELECT * FROM users WHERE username='" + username + "'".

Task: Identify if the code is vulnerable to SQL injection. Explain the attack vector.
Provide a fixed version using parameterized queries.

Format:
1. Vulnerable line (with line number if visible)
2. Attack example (a working malicious input string)
3. Fixed code snippet
4. CVSS v3.1 base score with justification

The AI knows its role, the exact stack, what to produce, and how to structure it.

Example 2 - Incident Response: AWS Privilege Escalation

Role: You are a cloud IR specialist with deep expertise in AWS IAM, CloudTrail, and MITRE ATT&CK for Cloud.

Context: At 02:14 UTC, CloudTrail logged 47 AssumeRole calls from EC2 instance i-0a1b2c3d4e5f
using role arn:aws:iam::123456789012:role/dev-ec2-role targeting arn:aws:iam::123456789012:role/prod-admin-role.
S3 GetObject calls to prod-data-bucket followed within 90 seconds.
No prior AssumeRole activity exists for this instance in the last 30 days.

Task: Determine if this is a privilege escalation attack. Assess the blast radius.
Provide immediate containment steps.

Format:
1. Attack classification (MITRE technique ID if applicable)
2. Blast radius - what was likely accessed or modified
3. Containment actions ordered by urgency
4. Evidence to preserve before any remediation

Framework #2 - Chain-of-Thought (CoT) Prompting

RCTF structures the input, but CoT structures the reasoning

CoT forces the AI to think step by step before reaching a conclusion, you can use CoT when the task involves multi-step analysis

Example 1 - SQL Injection Vulnerability Review

Think step by step before answering:

Step 1 - Detect: Is there unsanitized user input reaching a SQL query directly?
Step 2 - Classify: What type of injection is this? Error-based, blind, or time-based?
Step 3 - Impact: What data or operations are at risk if exploited?
Step 4 - Fix: What is the correct parameterized query or ORM method to remediate this?

Now review this code at @payment_service

The AI follow the step 1 by 1, each step narrows the answer before it commits

Example 2 - Incident Response: AWS Privilege Escalation

Think step by step before answering:

Step 1 - Timeline: Reconstruct the sequence of API calls from the CloudTrail events below.
Step 2 - Blast radius: What AWS resources were accessed or modified after the AssumeRole?
Step 3 - Containment: What IAM action stops further privilege escalation right now?
Step 4 - Remediation: What policy change prevents this role chain from being exploited again?

CloudTrail events @cloudtrail.json

CoT is especially useful here. Privilege escalation IR has too many variables for a one-shot answer. Walking the steps forces the AI to reason before it recommends containment.

Too Lazy to Write a Good Prompt? Use a Prompt Optimizer

Writing a full RCTF prompt from scratch takes effort. Sometimes you have a rough idea but don't want to structure it manually

Use the AI to fix the prompt for you

A prompt optimizer is a meta-prompt that generate a structured, improved version that you can use for your actual task

The Meta-Prompt Template

I have a rough security engineering prompt. Improve it using the RCTF framework.

Add:
- A specific Role (name the security domain and specialization)
- Relevant Context (technical stack, environment, what happened)
- A precise, scoped Task (one clear action)
- A structured Format (numbered output sections)

Do not change the intent of the original prompt.
Do not add information I didn't provide - flag gaps instead.

Here is my rough prompt:
[paste your bad prompt here]

Example

Rough prompt (bad):

"Review my code for SQL injection."

After running through the optimizer, you get:

You are a senior application security engineer specializing in OWASP Top 10.

The codebase location:
@payment_service/auth

Review the code below for SQL injection vulnerabilities.

Identify the vulnerable line,
explain the attack vector,
provide a fixed version,
and estimate a CVSS v3.1 score.

Return:
- Vulnerable line
- Attack example
- Fixed code
- CVSS score

The optimizer flags that you didn't provide the stack. It holds a placeholder. You fill it in. Done.

When to use this: Starting from a rough idea, converting a ticket title into a prompt, or when you're under time pressure during an incident.

Quick Reference Checklist

Before sending any security prompt, check these:

  • [x] Role defined with a specific security domain?

  • [x] Environment and stack specified?

  • [x] Task is scoped to one action?

  • [x] Output format defined?

  • [x] Multi-step reasoning required? → Use CoT

  • [x] Short on time? → Run rough prompt through the optimizer first

Further Reading

MCP Servers:

Skills & Agents:

Config Management:

Conclusion

Bad prompts produce generic answers, and generic answers waste time

Good prompts are specific. They give the AI a role, a technical environment, a scoped task, and a defined output structure.

Use RCTF when you need a structured, one-shot prompt. Use Chain-of-Thought when the task requires multi-step reasoning. Use the prompt optimizer when you have a rough idea and want a running start

Ready to apply AI to your Security Engineering?

Subscribe to Secengai Newsletter for weekly actionable content on AI for security engineers.

This content reflects personal views, experiments, and use cases in AI and security engineering. It does not represent any employer's positions, policies, or practices.

Keep Reading