Automated summary
Writes, explains, and optimises KQL queries for Azure Log Analytics, Application Insights, and Azure Monitor.
Strengths
- Enforces a readable, performant operator order (where first, project last)
- Gives concrete performance rules: has over contains, filter on TimeGenerated, materialize() for reused subqueries
- Ships ready-to-adapt patterns (error rate over time, p95 latency, correlated exceptions, pod restarts, Azure AD sign-in failures)
- Asks for the target service, time range, and output shape before generating a query
Limitations
- The skill file is truncated: the last example (sign-in failures) cuts off mid-clause
- No automated validation or execution of the query, so correctness relies on the model
- Assumes familiarity with Azure table names; multi-resource and multi-workspace cases are only lightly covered
Reach for it whenever you need to write, fix, explain, or speed up a KQL query over Azure logs or metrics.
For non-Kusto databases (SQL, Elasticsearch, Splunk) or Azure architecture questions that don't involve querying logs.
Security analysis
SafeThe skill is purely instructional documentation for authoring KQL queries. It declares no allowed-tools and contains no commands that execute, download, delete, or transmit data — only example query text and Azure documentation links. The only external reference is a link to official Microsoft Learn docs, which is benign.
No concerns found
How this analysis is madeExamples
Write a KQL query for Application Insights that shows the request error rate per 5-minute bin over the last 6 hours, ordered chronologically.Give me a KQL query against AppRequests that lists the 20 slowest operations over the last 24 hours with p50, p95, and p99 latency plus request counts.This KQL query against SecurityEvent is taking minutes to return. Explain what it does and rewrite it to be faster without changing the results.KQL Query Builder
Write, explain, and optimise Kusto Query Language (KQL) queries for Azure Log Analytics, Application Insights, and Azure Monitor.
Trigger
Use this skill when the user asks to:
- Write or generate a KQL query
- Debug or fix a failing/slow KQL query
- Explain what a KQL query does
- Optimise query performance
- Find logs, traces, exceptions, metrics, or alerts in Azure
- Query specific tables:
AzureDiagnostics,AppRequests,AppExceptions,Heartbeat,ContainerLog,SecurityEvent,AuditLogs,SigninLogs,Perf,Usage, etc.
Instructions
Before writing a query
Ask (or infer from context) the following if not already provided:
- Target service — Log Analytics workspace, Application Insights, or Azure Monitor Metrics?
- Time range — default to
last 24h(ago(24h)) if unspecified - What to find — errors, latency, a specific operation, a resource, a user, a correlation ID?
- Output shape — raw rows, aggregated counts, a time-series chart, a top-N list?
Query construction rules
Always follow this order of operators for readability and performance:
TableName
| where (filter first — reduces row count early)
| where (additional filters on the same pass when possible)
| extend (computed columns)
| summarize (aggregations)
| order by / top
| project (select only needed columns — always last)
Performance rules (apply to every query):
- Put the most selective
whereclause first - Prefer
hasovercontainsfor string matching (uses the index) - Prefer
==over=~when case sensitivity is acceptable - Avoid
*inproject— name columns explicitly - Use
materialize()when the same subquery is referenced more than once - For large tables, always filter on
TimeGeneratedbefore any other column - Prefer
summarize ... by bin(TimeGenerated, 5m)over looping client-side
Correctness rules:
- Wrap column names with spaces in
['Column Name'] - Use
isnotempty()not!= "" - Use
toint(),toreal(),todatetime()for explicit casts rather than implicit coercion - In Application Insights queries use
union isfuzzy=truewhen spanning multiple resources - Use
letstatements to define reusable sub-expressions and make intent clear
Output format
Return:
- The query in a fenced KQL code block
- A brief explanation (one sentence per operator) so the user can adapt it
- Any caveats (permissions needed, table retention limits, sampling effects in Application Insights, etc.)
When the user wants a parameterised query, use let variables at the top:
let _timeRange = 24h;
let _resourceGroup = "my-rg";
// ... rest of query
Common patterns
Error rate over time
AppRequests
| where TimeGenerated > ago(1h)
| summarize
Total = count(),
Errors = countif(Success == false)
by bin(TimeGenerated, 5m)
| extend ErrorRate = round(100.0 * Errors / Total, 2)
| order by TimeGenerated asc
Slowest operations (p95 latency)
AppRequests
| where TimeGenerated > ago(24h)
| summarize
p50 = percentile(DurationMs, 50),
p95 = percentile(DurationMs, 95),
p99 = percentile(DurationMs, 99),
RequestCount = count()
by Name
| order by p95 desc
| take 20
Exception details with correlation
AppExceptions
| where TimeGenerated > ago(6h)
| where OuterType has "ArgumentNullException" or SeverityLevel >= 3
| project TimeGenerated, OperationId, OuterType, OuterMessage, Assembly, FileName, LineNumber
| order by TimeGenerated desc
Kubernetes pod restarts (Container Insights)
KubePodInventory
| where TimeGenerated > ago(1h)
| where RestartCount > 0
| summarize MaxRestarts = max(RestartCount) by Name, Namespace, bin(TimeGenerated, 5m)
| order by MaxRestarts desc
Azure AD sign-in failures
SigninLogs
| where TimeGenerated > ago(24h)
| where ResultType != "0"
| summarize FailureCount = count() by UserPrincipalName, ResultDescription, AppDisplayName
| order by FailureCount desc
| take 50
Resource health events
AzureActivity
| where TimeGenerated > ago(7d)
| where ActivityStatusValue in ("Failed", "Critical")
| project TimeGenerated, OperationNameValue, ResourceGroup, ResourceId, Caller, ActivityStatusValue, Properties
| order by TimeGenerated desc
Alert rule — threshold over 5-minute window
Perf
| where TimeGenerated > ago(5m)
| where ObjectName == "Processor" and CounterName == "% Processor Time"
| where InstanceName == "_Total"
| summarize AvgCPU = avg(CounterValue) by Computer
| where AvgCPU > 85
Explaining an existing query
When the user pastes a query and asks what it does:
- Identify the source table and the data domain
- Walk through each operator in order, one sentence each
- State what the final output shape is (columns, sort order, row limit)
- Flag any performance or correctness concerns
Debugging a query
When the user reports an error or unexpected results:
- Check operator order (filter → aggregate → project)
- Verify column name casing (KQL column names are case-sensitive)
- Check time range —
ago()is relative to query execution time - Check for implicit type mismatches (string vs. int comparisons)
- Suggest
take 10on intermediate steps to inspect intermediate rows - For "no results": relax filters one by one to find where data disappears
References
- KQL quick reference
- Common Log Analytics tables
- Query performance patterns
- Official docs: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/kql-query-builder-ms1aw5f0/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/kql-query-builder-ms1aw5f0' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/kql-query-builder-ms1aw5f0/download' --output '.skill-downloads/kql-query-builder-ms1aw5f0/SKILL.md.part' && mv '.skill-downloads/kql-query-builder-ms1aw5f0/SKILL.md.part' '.skill-downloads/kql-query-builder-ms1aw5f0/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
This file does not provide a usable name/description header for this native procedure. It remains available to download and inspect; use the manual method below.
Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/kql-query-builder-ms1aw5f0/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
Configure a Chat Channel with SecretRefs
DevOps
Set up chat channels using non-interactive commands, with secrets only as SecretRefs. Covers gather, mutate, repair, and prove steps for reliable delivery.
Investigate ClickHouse CI Failures
DevOps
Investigate a ClickHouse CI failure end-to-end from a PR or S3 report URL. Fetches failed tests, classifies flaky vs real regression, and checks for existing issues/fixes.
Ansible PR Review
DevOps
Reviews an Ansible PR following the project's standardized process, including changelog checks, test coverage validation, and feedback tracking.