Writing Sigma Rules That Work: Validation and Testing Before You Convert
A practical guide to Sigma detection rules: structure, condition syntax, modifiers, common mistakes and testing a rule against sample events.

Writing Sigma Rules That Work: Validation and Testing Before You Convert
Sigma is to log detections what YARA is to files: a shared, vendor-neutral format. A Sigma rule is a YAML file that says which log source to look at and which field values to match, and converters such as pySigma turn it into a query for Splunk, Elastic, Microsoft Sentinel and many others. Because one rule can feed many platforms, a small mistake travels far. This guide covers the structure, the usual errors and how to test a rule before converting it.
The structure of a rule
A Sigma rule has three required parts and several recommended ones.
- title: short and specific, such as Suspicious Encoded PowerShell Command Line.
- logsource: which data the rule applies to, described with category (process_creation, network_connection), product (windows, linux) and service (security, sysmon).
- detection: one or more search identifiers plus a condition.
Recommended metadata includes a random UUID id, status (stable, test, experimental, deprecated or unsupported), level (informational to critical), description, author, date in YYYY-MM-DD form, references, falsepositives and tags such as attack.execution or attack.t1059.001.
Search identifiers and modifiers
Each search identifier is a map of fields to values, or a list of such maps. Inside a map, all fields must match (and). A list of values for one field means any of them (or). Modifiers after a pipe change how values compare: contains, startswith and endswith add wildcards, all requires every value in a list, re uses a regular expression, cidr matches network ranges, and windash also matches the slash and dash variants Windows tools accept. Matching is case-insensitive by default.
The condition
The condition combines identifiers with and, or, not and parentheses. Patterns save typing: 1 of selection_* means any identifier starting with selection_, and all of them means every identifier. A typical layout is all of selection_* and not 1 of filter_*, with filters that remove known benign activity.
Common mistakes
- A misspelled modifier, such as endswithh, which converters reject.
- A condition naming an identifier that does not exist, often after renaming one.
- A filter defined but never used in the condition, so the false positives it was meant to remove still fire.
- Tags in the wrong form, such as attack.defense_evasion with an underscore.
- Leading or trailing wildcards inside a contains value, which are redundant.
- Old Sigma 1.x features such as condition lists or count aggregations, which Sigma 2.0 moves to correlation rules.
Test before you convert
Validation tells you the rule is well formed; testing tells you it does what you meant. Collect a handful of real events: some that should match, some that should not, and at least one from the benign source your filter is meant to exclude. Run the rule logic against them and check each result.
The Sigma Rule Validator and Tester does both in the browser. Paste one or more rules separated by ---, and it checks metadata, log source, identifiers, modifiers, regular expressions, CIDR values, tags and the condition grammar, with errors, warnings and notices for each. The test tab takes events as JSON lines and evaluates the rule with Sigma's matching rules, showing which events match and which selections were true for each. When the results look right, download the corrected rule and convert it with pySigma or sigma-cli.
Field names are the hidden trap
A rule written with Sysmon field names such as Image and CommandLine will only match in a SIEM that maps its own field names to those, through a processing pipeline in the converter. Always test the converted query in the target platform, on real data, before you rely on it.
Keep rules maintainable
Give every rule an id and keep it when you edit; raise the modified date; document false positives honestly; and prefer several focused rules over one huge condition. Detection content is code, and it deserves the same reviews and tests.



