A Sigma rule is a YAML file built from three required parts: metadata, logsource, and detection. To write one, you pick a specific behavior, copy a template from the Sigma rules specification, write your selection blocks, validate syntax, convert with sigma-cli, and run the result in audit mode before it ever fires an alert.
That’s the whole workflow, stripped to its bones. Everything else in this article is detail on how to do each step well.
Here’s what to do in the next ten minutes if you want to start now:
- Clone the SigmaHQ repository and browse
rules/for something close to your target behavior. - Open a rule template in VS Code with the Sigma extension installed for live linting.
- Run a local conversion with sigma-cli against your SIEM’s pipeline to confirm the syntax parses before you write a single line of custom logic.
The Sigma specification and sigma-cli aren’t optional extras. They’re the two artifacts that separate a rule that looks correct from one that actually converts and runs.
Key Takeaways
Writing a working Sigma rule requires SigmaHQ template reuse, precise field mapping through the correct pipeline, and a mandatory audit period before any alert goes live.
| Point | Details |
|---|---|
| Start from a template | Copy a similar rule from the SigmaHQ repository rather than writing detection logic from scratch. |
| Get the pipeline right | Match your -p flag to your SIEM backend, since field mappings differ per pipeline and cause silent failures. |
| Prefer generic over IOC-specific | Technique-focused rules stay useful after adversaries rotate indicators; IOC-only rules expire fast. |
| Audit before you alert | Run new rules in audit mode for a typical audit period that covers a full business cycle, label matches, and filter the top false-positive sources first. |
| Track triage load, not just matches | A rising match rate with flat analyst triage time usually signals a filter gap, not new attacker activity. |
Table of Contents
- How Do You Prepare Your Environment to Write Sigma Rules?
- What Fields Does a Sigma Rule File Actually Need?
- What’s the Step-by-Step Process to Write a Sigma Rule?
- How Do You Test and Convert a Sigma Rule Before Deployment?
- How Do You Keep Sigma Rules Tuned Once They’re Live?
- What Do Real Sigma Rule Examples Look Like?
- How Does Blue Team Academy Help You Write Better Sigma Rules?
- The Part Most Sigma Guides Skip
- Frequently Asked Questions
- Sources
How Do You Prepare Your Environment to Write Sigma Rules?
You need four things before you write a single detection: the repository, a converter, an editor with live validation, and a test index to throw queries against. Skipping any one of these means you’ll debug syntax errors in production instead of on your laptop.
Start by cloning the SigmaHQ repository. It’s not just a rule library, it’s the reference implementation of file layout, naming conventions, and pipeline structure that every serious Sigma author works from. Copying an existing rule that already matches your target technique saves hours over writing from a blank file.
Here’s the setup sequence that gets you productive fastest:
- Clone the repo and note the
rules/andrules-emerging-threats/folders as your template sources. - Install sigma-cli, the official converter, or use a hosted alternative like sigconverter.io or Detection Studio for quick one-off checks.
- Install the official Sigma extension in VS Code for schema validation, autocomplete, and inline error highlighting as you type.
- Confirm you know which pipeline (
-pflag) matches your SIEM, since pipelines control how logical field names map to your actual index fields. - Point sigma-cli at a test index or sample query environment so conversions can be sanity checked before deployment.
Missing the pipeline step is the single most common reason a rule “works” syntactically but returns zero results, or worse, errors, once it hits a real SIEM query.
Pro Tip: Keep a scratch folder of three or four pipeline configs for the SIEMs you support. Swapping -p values to test the same rule against different backends takes seconds and catches field-mapping mistakes before an analyst ever sees a broken alert.
What Fields Does a Sigma Rule File Actually Need?
Every Sigma rule breaks into five parts, and skipping any of them either breaks conversion or leaves the analyst who inherits your rule with zero context six months from now.

Metadata comes first. Give the rule a descriptive title (not “Suspicious Activity,” something like “Possible LSASS Access via Uncommon Process”), a unique id (UUID4), a status from the standard vocabulary (experimental, test, stable, deprecated, unsupported), a plain-English description, author, date, and modified fields, and references pointing to the technique writeup or incident that prompted the rule. tags should include the relevant MITRE ATT&CK technique ID, which lets your SIEM dashboard aggregate coverage by tactic later.
Logsource defines where the rule looks. The category, product, and service fields tell the converter which pipeline mapping to apply, which is exactly why getting this wrong produces a rule that parses fine but queries the wrong index entirely.
Detection is the logic itself, and this is where most authoring time goes. You write one or more named selection blocks, then a condition expression that combines them (selection and not filter, 1 of selection_*, etc.). Value modifiers refine matches: contains, startswith, endswith, re for regex, and all/any for list logic against multiple values.
Aggregation syntax extends this for volume-based techniques. A Kerberoasting or brute-force detection typically looks like count() by TargetUserName > 5 within 10m. Choosing the grouping field matters more than it looks: group by the wrong field and you either drown in noise or miss the pattern entirely, a cardinality problem documented in SigmaHQ’s own rule creation guidance.
Finally, falsepositives should list realistic legitimate triggers (not just “none”), and level should reflect actual severity, not maximum panic.
Pro Tip: Write your falsepositives field before you write the detection logic. If you can’t name at least one plausible benign trigger, you probably haven’t thought hard enough about the behavior yet.
What’s the Step-by-Step Process to Write a Sigma Rule?
Writing a Sigma rule that survives contact with a real environment follows a consistent recipe. Here’s the order that avoids the most rework:
- Define the behavior and target logsource. Be specific: “PowerShell downloading and executing a remote script” beats “suspicious PowerShell.”
- Choose the correct category, product, and service. This decision drives every field mapping downstream, so get it right before writing detection logic.
- Find a comparable rule in the SigmaHQ repository and copy its structure rather than starting from a blank file.
- Adapt the selection blocks to your specific fields and values, checking field names against your actual log schema rather than assuming they match the template.
- Map field names through your pipeline, and prefer field-specific matches (
CommandLine|contains) over broad keyword-only searches that ignore context. - Write the condition expression clearly, then add a filter block for known legitimate activity you already know exists in your environment.
- Fill in metadata, attach MITRE ATT&CK tags, add references, then run VS Code validation followed by
sigma convertto confirm the syntax and pipeline mapping both check out.
A few habits separate rules that hold up from rules that get disabled within a week:
- Prefer generic, technique-focused logic over IOC-specific values, since detection engineers who build for the technique rather than the indicator keep their rules useful long after the original indicator rotates out.
- Write the condition expression so a second analyst can read it without opening the wiki.
- Add filters for known-legitimate activity at authoring time, not after the first noisy alert.
How Do You Test and Convert a Sigma Rule Before Deployment?
Validation happens in three passes: syntax, conversion, and behavior in the wild. Skipping straight to deployment is how noisy rules end up disabled by week two.
- Run
sigma convertwith the correct pipeline and check for parse errors or field mismatches. A clean conversion with zero warnings is the minimum bar, not the finish line. - Validate in VS Code using the Sigma extension before you even touch the CLI, since it catches schema violations (missing required fields, malformed condition syntax) instantly.
- Add a CI validation step. Running
sigma convertas a pre-deploy check means broken queries and unmapped fields get caught in the pipeline instead of in your SOC’s alert queue. - Deploy in audit mode first. Let the rule run silently, collecting matches without generating analyst-facing alerts.
- Collect matches for roughly 14 days, a window long enough to capture weekly business cycles like patch Tuesday or batch jobs that spike on specific days.
- Label every match true positive or false positive, then build a minimal filter to exclude the top sources responsible for most of the noise, a pattern SigmaHQ documents directly in its operational guidance.
- Promote to alerting once you hit an acceptable true positive rate, manageable match volume, and low enough noise that the analyst on shift trusts the rule instead of dismissing it on sight.
Pro Tip: Track your audit-to-promotion ratio across all your rules. If most of what you write in a given quarter never makes it past audit mode, that’s a signal your selection logic is too broad, not that your environment is unusually noisy.
How Do You Keep Sigma Rules Tuned Once They’re Live?
A rule that fires cleanly in week one and drowns analysts in week four hasn’t failed, it just hasn’t been tuned yet. Tuning is ongoing maintenance, not a one-time step.
- Add explicit filters for known-okay sources: admin jump boxes, automation service accounts, backup agents. A filter block like
filter_admin: User|contains: 'svc_backup'combined withcondition: selection and not filter_adminhandles the most common allowlist pattern. - Set
levelbased on how commonly the underlying tool gets used legitimately in your environment. A PsExec detection might behighin a shop that’s banned it andmediumsomewhere it’s still part of normal admin workflow. - Move rules through the status lifecycle deliberately:
experimentalwhile you’re still shaping the logic,testonce it’s in audit mode,stableonly after it’s proven itself against real traffic. - Track match rate and analyst triage load as your core operational metrics. A rule with a rising match rate but flat triage time is probably feeding a filter gap, not an actual increase in adversary activity.
Pro Tip: When a stable rule suddenly starts firing more, check for an infrastructure change (a new automation tool, a migrated log source) before you assume it’s a real detection. Regressions in tuning usually come from your own environment shifting under the rule, not from a new attacker technique.
What Do Real Sigma Rule Examples Look Like?
Two patterns cover most of what you’ll write day to day: a straightforward field match and a volume-based aggregation.
- Basic field-value detection. A rule targeting suspicious LSASS access might use
logsource: category: process_access, product: windows, aselectionblock matchingTargetImage|endswith: 'lsass.exe'combined with an uncommonSourceImage, andcondition: selection. Each field maps directly to a Sysmon Event ID 10 record, which is why gettingcategoryright matters so much for the converter. - Aggregation-based detection. A Kerberoasting rule uses
count() by TargetUserName > 5 within 10magainst Windows Security Event ID 4769 with an unusual encryption type. Tuning note: group byTargetUserName, notComputer, or you’ll miss the pattern when a single account gets targeted from multiple hosts.
Before deploying any new rule, run this checklist:
- Confirm every field name in your selection blocks exists in your actual log schema, not just the template’s.
- Re-verify the pipeline mapping matches your SIEM backend.
- Fill in realistic
falsepositives, not a placeholder. - Run
sigma convertone final time after any last-minute edit.
How Does Blue Team Academy Help You Write Better Sigma Rules?
Writing a technically correct rule and writing one an analyst can actually trust are two different skills, and that gap is exactly what Blue Team Academy’s Threat and Control Method closes. The framework forces you to name the specific control gap before you write detection logic, which is the same discipline that keeps a Sigma rule generic and technique-focused instead of a brittle, indicator-chasing one-off.
Course features that map directly onto this workflow:
- Generative AI-assisted templates that speed up first-draft rule authoring.
- Peer-reviewed labs where detection logic gets critiqued before it ever reaches production.
- Practical exercises built around real logsource categories, not abstract theory.
If you’re making the jump from general IT into a detection engineering role, the From IT to Cybersecurity program builds this exact skill set into a structured path.
The Part Most Sigma Guides Skip
Most tutorials treat writing a Sigma rule as a syntax exercise: get the YAML valid, get it to convert, ship it. That’s necessary but nowhere near sufficient. The rule that actually protects an environment is the one somebody tuned for two weeks in audit mode and trimmed down to a manageable, trustworthy signal.
The conventional advice oversells the writing and undersells the tuning. Anyone can copy a SigmaHQ template and adapt field names in twenty minutes. The real skill, the one that separates a detection engineer from someone who can technically write YAML, is knowing which grouping field avoids a cardinality trap in an aggregation rule, or recognizing that a medium severity in one environment is a high in another because of how commonly a tool gets used legitimately.
If you take one thing from this, prioritize the audit period over the initial write. A mediocre first draft that gets two weeks of honest tuning beats a clever first draft nobody ever revisits. Training that includes peer review, like the labs built into Blue Team Academy’s courses, accelerates this because someone else catches the cardinality trap before production does.

Frequently Asked Questions
Do I need to know regular expressions to write Sigma rules?
Not for most rules. Value modifiers like contains, startswith, and endswith cover the majority of field matches. The re modifier exists for regex when you need it, but plenty of solid, production-ready rules never touch it.
What’s the difference between Sigma detection rules and sigma notation in math?
They’re unrelated. Sigma detection rules are YAML files for log-based threat detection, while sigma (Σ) in mathematics denotes summation. The shared name is coincidental and worth clarifying if you’re searching and getting mixed results.
Can I convert one Sigma rule to multiple SIEM query languages?
Yes. That’s the entire point of the format. Running sigma-cli with different pipeline flags against the same rule file produces SIEM-native syntax for each backend without rewriting the detection logic.
How specific should a Sigma rule’s logsource be?
As specific as your log source actually supports. A rule scoped to category: process_creation, product: windows will map more predictably through converters than a vague or overly broad logsource definition.
Where should I start if I’ve never written a Sigma rule before?
Clone the SigmaHQ repository, find an existing rule closest to a behavior you already understand well, and adapt it field by field rather than starting from an empty file. Readers building this skill as part of a broader career shift into detection engineering often pair that hands-on practice with structured coursework like Blue Team Academy’s From IT to Cybersecurity program.

