This prompt is a pre-flight safety check for CI/CD operators, workflow engine developers, and agent architects who need to validate formal workflow definitions before they are executed. Its primary job is to analyze a provided workflow specification—typically in YAML, JSON, or a domain-specific language (DSL)—and identify structural concurrency hazards that would cause the workflow to stall. These hazards include resource-wait cycles (where Task A waits for a lock held by Task B, which is waiting for Task A), mutex conflicts, and ordering deadlocks. The ideal user is someone responsible for production workflow reliability who wants a fast, LLM-powered linting step to catch these problems before they become incidents requiring manual intervention.
Prompt
Deadlock Detection Prompt for Workflow Definitions

When to Use This Prompt
Understand the ideal use cases, required inputs, and critical limitations of the deadlock detection prompt before integrating it into your CI/CD pipeline.
To use this prompt effectively, you must provide a complete, machine-readable workflow definition as the [WORKFLOW_DEFINITION] input. This definition must explicitly declare tasks, their dependencies, and any resource locks or mutexes they acquire. The prompt is not designed to infer dependencies from natural language descriptions or to analyze runtime logs; it performs a static analysis of the declared structure. You should wire this prompt into your deployment pipeline as a gating step, where a failure blocks the workflow from being deployed to production. The output includes a severity classification for each detected deadlock and a recommended resolution, but this guidance should be treated as a suggestion for a human operator to review, not as an automated fix.
Do not use this prompt as a replacement for a formal model checker like TLA+ or a dedicated static analysis tool for your workflow engine. It is a fast, probabilistic safety net, not a proof of correctness. It may miss deadlocks that arise from complex temporal logic, dynamic resource creation, or conditions not fully expressed in the static definition. It is also not suitable for analyzing workflows defined only in natural language or for detecting performance bottlenecks that are not strict deadlocks. In high-risk environments where a stalled workflow could cause significant financial, operational, or safety impact, you must combine this prompt with deterministic validation tools and a mandatory human review step before any workflow is promoted to production.
Use Case Fit
Where the Deadlock Detection Prompt works, where it fails, and what you need before you start.
Good Fit: Formal Workflow Definitions
Use when: you have a machine-readable workflow definition (YAML, JSON, DSL) with explicit resource locks, mutexes, or step ordering constraints. The prompt excels at static analysis of declared dependencies. Guardrail: validate that the input schema matches one of the supported formats before sending to the model.
Bad Fit: Implicit or Undocumented Dependencies
Avoid when: dependencies exist only in runtime behavior, tribal knowledge, or undocumented side effects. The prompt cannot detect deadlocks caused by unmodeled resource contention. Guardrail: require a human-in-the-loop review of any workflow where the formal definition is known to be incomplete or stale.
Required Input: Structured Workflow Spec
Risk: garbage-in, garbage-out. If the workflow definition is malformed, ambiguous, or uses non-standard DSL constructs, the model will hallucinate dependencies or miss real cycles. Guardrail: run a schema validator and a linter before passing the definition to the prompt. Reject inputs that fail strict parsing.
Operational Risk: False Negatives in Large Graphs
Risk: for workflows with hundreds of nodes, the model may miss subtle transitive deadlocks or resource-wait cycles that span many steps. Attention dilution increases with graph size. Guardrail: pair the prompt with a deterministic graph-cycle detection algorithm. Use the model for explanation and severity classification, not as the sole detection engine.
Operational Risk: Over-Confident Severity Labels
Risk: the model may classify a theoretical deadlock as 'critical' when it is unreachable in practice, or label a real production deadlock as 'low severity' due to missing context about blast radius. Guardrail: always route severity classifications through a human reviewer before triggering automated pipeline halts or pager alerts.
Integration Fit: CI/CD Pipeline Gates
Use when: you want a pre-merge or pre-deploy check that catches ordering bugs before they reach production. The prompt fits naturally as a non-blocking advisory step. Avoid when: you need sub-second latency for every commit. Guardrail: cache results for unchanged workflow files and set a generous timeout to avoid pipeline stalls.
Copy-Ready Prompt Template
A ready-to-use prompt template for detecting deadlocks in workflow definitions, with placeholders for your specific workflow DSL and constraints.
The following prompt template is designed to be copied directly into your application or testing harness. It accepts a formal workflow definition and returns a structured deadlock analysis. The template uses square-bracket placeholders that you must replace with your specific workflow content, output schema requirements, and any additional constraints before sending it to the model. Do not ship this template with unresolved placeholders in production—your harness should validate that all required fields are populated before the API call.
textAnalyze the following workflow definition for deadlocks. A deadlock is a condition where two or more steps are waiting for each other to release a resource or complete, creating a cycle that prevents any of them from proceeding. Check for: - Resource-wait cycles: steps holding resources while waiting for resources held by other steps - Mutex conflicts: steps competing for exclusive access to the same resource - Ordering deadlocks: steps that cannot proceed because their prerequisites form a cycle [WORKFLOW_DEFINITION] Classify the severity of each finding as 'BLOCKER', 'WARNING', or 'INFO' using these criteria: - BLOCKER: A confirmed cycle that will prevent workflow completion under all execution paths - WARNING: A potential deadlock that depends on runtime conditions or resource availability - INFO: A structural concern that does not currently form a cycle but could become one after changes For each finding, provide: 1. The severity classification 2. The specific steps or resources involved in the cycle 3. A clear description of the wait chain 4. A resolution recommendation [OUTPUT_SCHEMA] [CONSTRAINTS] If no deadlocks are found, state that explicitly and explain why the workflow is deadlock-free.
To adapt this template for your system, replace [WORKFLOW_DEFINITION] with the actual YAML, JSON, or DSL representation of your workflow. The [OUTPUT_SCHEMA] placeholder should contain your expected JSON structure—for example, an array of finding objects with fields for severity, cycle_path, description, and recommendation. The [CONSTRAINTS] placeholder is where you add domain-specific rules, such as maximum resource counts, known mutex groups, or assumptions about your execution environment's concurrency model. If your workflow engine has known limitations—like a maximum number of parallel steps or specific resource types that cannot be shared—include those here to prevent false positives.
Before deploying this prompt, build a validation layer that checks the model's output against your [OUTPUT_SCHEMA]. A malformed severity field or a missing cycle_path on a BLOCKER finding should trigger a retry or fallback. For high-risk workflows where a missed deadlock could cause production outages, route all BLOCKER findings to a human reviewer before accepting automated resolution recommendations. The model can identify the cycle, but the decision to restructure dependencies or change resource allocation should remain a human judgment call when the workflow is customer-facing or revenue-critical.
Prompt Variables
Required inputs for the deadlock detection prompt. Each placeholder must be populated before the prompt is sent. Validation notes describe how to verify the input is well-formed before incurring model cost.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[WORKFLOW_DEFINITION] | The complete workflow specification to analyze, provided as a raw string. Accepts YAML, JSON, or DSL formats. | jobs: build: needs: [test] test: needs: [build] | Parse check: must be valid YAML, JSON, or known DSL. Reject empty strings. If the definition exceeds 8,000 tokens, chunk by job/resource boundary and analyze segments independently. |
[DEFINITION_FORMAT] | Explicit format hint for the parser. Prevents the model from guessing the format and misinterpreting structure. | yaml | Enum check: must be one of 'yaml', 'json', 'dsl_github_actions', 'dsl_gitlab_ci', 'dsl_circleci', 'dsl_custom'. If 'dsl_custom', the [CUSTOM_DSL_SPEC] placeholder becomes required. |
[CUSTOM_DSL_SPEC] | A description of the custom DSL syntax when [DEFINITION_FORMAT] is 'dsl_custom'. Defines how dependencies, resources, and mutexes are declared. | Tasks declare dependencies via 'requires: [task_id]'. Mutexes are declared via 'lock: [resource_name]'. | Required when [DEFINITION_FORMAT] equals 'dsl_custom', otherwise null. Must include dependency declaration syntax, resource locking syntax, and any implicit ordering rules. |
[RESOURCE_POOLS] | A list of shared resources with concurrency limits that tasks may contend for. Used to detect resource-wait cycles beyond explicit task dependencies. | [{"name": "deploy_env_staging", "max_concurrent": 1}, {"name": "db_migration_lock", "max_concurrent": 1}] | Schema check: must be a JSON array of objects with 'name' (string) and 'max_concurrent' (integer >= 1). Null allowed if no shared resources exist. Empty array means no resource constraints. |
[ANALYSIS_DEPTH] | Controls how exhaustively the prompt searches for deadlocks. Higher depth catches transitive resource-wait cycles but increases token cost and latency. | exhaustive | Enum check: must be 'basic' (direct dependency cycles only), 'standard' (includes single-hop resource waits), or 'exhaustive' (full transitive closure over dependencies and resources). Default to 'standard' if not specified. |
[OUTPUT_SCHEMA] | The expected JSON schema for the deadlock report. Ensures the model returns structured, machine-readable results for downstream tooling. | {"deadlocks": [{"cycle": ["string"], "severity": "string", "cause": "string", "resolution": "string"}]} | Schema check: must be a valid JSON Schema object. The prompt harness should validate the model's response against this schema. If the response fails validation, retry with the schema re-emphasized in the retry prompt. |
[SEVERITY_THRESHOLD] | Minimum severity level to include in the report. Filters out low-priority findings to keep the output actionable. | warning | Enum check: must be 'info', 'warning', or 'critical'. Findings below this threshold are omitted from the deadlocks array but may appear in a separate 'suppressed_findings' field for auditability. |
Implementation Harness Notes
How to wire the deadlock detection prompt into a CI/CD pipeline, workflow validation service, or pre-deployment check with validation, retries, and human review gates.
The deadlock detection prompt is designed to operate as a synchronous validation step inside a larger workflow pipeline. You send a formal workflow definition (YAML, JSON, or DSL) as the [WORKFLOW_DEFINITION] input and receive a structured analysis containing detected cycles, severity classifications, and resolution guidance. This prompt should be called before any workflow is deployed, registered, or executed—not as a runtime monitor. The typical integration point is a CI/CD check, a workflow editor's pre-save hook, or a workflow engine's registration API validator. Because the output includes severity labels (BLOCKING, WARNING, INFO), your harness can make automated decisions: block deployment on BLOCKING findings, surface WARNING findings for review, and log INFO findings without interrupting the pipeline.
Validation and retry logic is critical because the model can produce malformed JSON, omit required fields, or generate cycle paths that don't match the input graph. Your harness must: (1) validate that the response is parseable JSON matching the [OUTPUT_SCHEMA]; (2) verify that every reported cycle path references nodes and edges that actually exist in the submitted workflow definition; (3) confirm that severity is one of the allowed enum values; and (4) check that resolution_guidance is present for every BLOCKING or WARNING finding. If validation fails, retry once with the same prompt plus the validation error message appended as context. If the second attempt also fails, escalate to a human reviewer with the raw model output and validation errors. For high-stakes production workflows (deployment pipelines, financial transaction systems, healthcare orchestration), require human approval on all BLOCKING findings regardless of model confidence.
Model choice and tool integration depend on your latency and accuracy requirements. For CI/CD pipelines where latency matters, use a fast model (GPT-4o, Claude 3.5 Sonnet) with temperature=0 and a strict JSON mode or structured output API. For offline batch analysis of large workflow repositories, you can use a slower but more thorough model and run multiple passes. The prompt does not require external tools or retrieval—it operates purely on the provided workflow definition. However, if your workflow definitions reference external resources (databases, APIs, queues) by name, consider providing a [RESOURCE_CATALOG] as additional context so the model can identify resource-wait cycles that span workflow steps and external system state. Log every invocation: input hash, model version, raw output, validation result, and reviewer decision. This audit trail is essential when a deadlock slips through and you need to improve the prompt or add a new detection pattern.
Next steps after integration: Start by running the prompt against your existing workflow library to establish a baseline—you'll likely find deadlocks that were previously undetected. Use those findings to tune the [CONSTRAINTS] section of the prompt, adding domain-specific deadlock patterns (e.g., 'two steps must never hold mutexes A and B in reverse order'). Build a regression test suite from confirmed deadlocks and confirmed false positives, and run it on every prompt change. If you observe the model missing deadlocks that involve external resource contention (database locks, API rate limits, queue capacity), supplement this prompt with a Resource Contention Prediction Prompt from the same playbook series rather than overloading this single prompt.
Expected Output Contract
Defines the required JSON schema for the deadlock detection output. Use this contract to validate the model response before passing results to a workflow engine or alerting system.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
deadlocks | Array of objects | Must be present, even if empty. Schema check: array. | |
deadlocks[].cycle_id | String | Non-empty string. Format: 'cycle-###'. Uniqueness check across all elements. | |
deadlocks[].cycle_path | Array of strings | Must contain at least 2 task or resource names. First and last element must be identical. | |
deadlocks[].severity | Enum: 'CRITICAL', 'HIGH', 'MEDIUM', 'LOW' | Must be one of the four defined values. CRITICAL reserved for cycles blocking a terminal task. | |
deadlocks[].resource_type | Enum: 'mutex', 'resource_wait', 'ordering' | Must match one of the three deadlock categories defined in the prompt. | |
deadlocks[].resolution | Object | Must contain 'suggested_break_link' (string) and 'rationale' (string). Neither field can be empty. | |
analysis_notes | String or null | If no deadlocks found, must be a non-empty summary confirming the check. If deadlocks found, can be null. |
Common Failure Modes
Deadlock detection prompts fail in predictable ways. These are the most common failure modes when analyzing workflow definitions for resource-wait cycles, mutex conflicts, and ordering deadlocks—and how to guard against each one.
Implicit Dependencies Missed
What to watch: The model only analyzes explicitly declared depends_on fields and misses dependencies created by shared resource access, queue names, or environment variables. A workflow with no declared dependencies can still deadlock on a mutex or database lock. Guardrail: Include a resource inventory in the prompt that maps every named resource (queues, locks, tables, APIs) to the steps that access them. Require the model to cross-reference resource access patterns, not just declared edges.
Cycle Detection on Wrong Abstraction Level
What to watch: The model detects cycles between high-level workflow stages but misses cycles at the job or task level within a stage. A DAG of stages can be acyclic while individual job dependencies form a deadlock. Guardrail: Require the prompt to analyze dependencies at the finest granularity present in the definition. Add a validation step that flattens all sub-workflows before cycle detection and rejects analysis that only operates on parent stages.
Conditional Deadlocks Ignored
What to watch: The model treats all dependency edges as always-active and misses deadlocks that only manifest under specific conditions (branch outcomes, retry paths, timeout fallbacks). A workflow that passes static analysis can deadlock when a specific error branch activates. Guardrail: Prompt the model to enumerate all conditional branches and analyze each path independently. Include a requirement to flag edges that are conditionally active and produce a separate deadlock assessment per execution path.
Severity Inflation or Deflation
What to watch: The model classifies every detected cycle as either critical (inflating alarm) or low-severity (suppressing real risks) without considering recovery paths, timeout guards, or manual intervention points. Guardrail: Provide a severity rubric in the prompt with concrete criteria: cycles with no timeout escape are critical, cycles with timeout-based recovery are medium, and cycles guarded by human approval gates are low. Require the model to justify each severity classification against the rubric.
Resolution Guidance Too Generic
What to watch: The model suggests breaking the cycle but doesn't specify which edge to remove, what reordering preserves correctness, or what resource contention is the root cause. Vague guidance forces the operator to re-analyze manually. Guardrail: Require the output to include a specific break point with justification, a before/after dependency comparison, and a list of downstream tasks affected by the change. Add a constraint that resolution guidance must reference concrete step IDs or resource names from the input definition.
Large Workflow Truncation
What to watch: Workflow definitions exceeding context windows cause the model to analyze only the first N steps, missing deadlocks in later stages or between early and late steps. Partial analysis produces false confidence. Guardrail: Add a pre-processing step that counts steps and warns if the definition exceeds a safe threshold. For large workflows, chunk by dependency subgraph and analyze each subgraph independently, then run a cross-subgraph dependency check. Prompt the model to explicitly state which step range it analyzed.
Evaluation Rubric
Use this rubric to test the deadlock detection prompt before integrating it into a CI/CD pipeline. Each criterion targets a specific failure mode common to dependency analysis prompts.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Cycle Detection Completeness | All cycles in the [WORKFLOW_DEFINITION] are identified with a unique cycle ID and full node path | A known cycle from the ground-truth test case is missing from the output | Run prompt against a YAML definition containing 3 known cycles; assert output.cycles.length equals 3 |
Severity Classification Accuracy | Each detected deadlock is classified as 'BLOCKING', 'WARNING', or 'INFO' matching the ground-truth label | A cycle that prevents workflow completion is labeled 'INFO' or 'WARNING' | Compare severity field for each cycle against pre-labeled test fixtures; require exact match on BLOCKING cycles |
Resource-Wait Cycle Identification | Cycles caused by mutex or resource locks include the resource name and conflicting task IDs | A mutex deadlock is reported as a generic dependency cycle without the resource name | Feed a workflow with two tasks waiting on the same named mutex; assert output includes resourceName field |
Resolution Guidance Actionability | Each deadlock includes a resolution suggestion that references a specific edge to break or reorder | Resolution field contains generic advice like 'fix the dependency' without naming the edge | Check that resolution text contains at least one task name or edge identifier from the cycle path |
False Positive Avoidance | No deadlock is reported for a valid acyclic dependency graph | Output contains one or more cycles when the input workflow is known to be acyclic | Run prompt against a validated DAG with 20+ nodes and no cycles; assert output.cycles is an empty array |
Output Schema Compliance | Output is valid JSON matching the [OUTPUT_SCHEMA] with all required fields present | Output is missing required fields, contains extra keys, or fails JSON parse | Validate output with a JSON Schema validator; reject if schema errors exist |
Edge Case: Single-Node Workflow | Prompt returns an empty cycle list and a summary indicating no deadlocks for a single-task workflow | Prompt hallucinates a cycle or returns a parsing error for minimal valid input | Submit a workflow definition with exactly one task and no dependencies; assert cycles is empty and no error field |
Edge Case: Self-Dependency | A task that lists itself as a prerequisite is flagged as a deadlock with severity 'BLOCKING' | Self-dependency is ignored or classified below BLOCKING severity | Include a task with 'depends_on: [self]' in a test fixture; assert at least one cycle includes that task as both source and target |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and a single workflow definition in YAML or JSON. Remove severity classification and resolution guidance sections. Focus only on cycle detection. Use a simple output schema: {"has_deadlock": boolean, "cycles": [{"path": [string], "description": string}]}. Run against 5-10 known workflow examples manually.
Prompt modification
Replace the full output schema with:
code[OUTPUT_SCHEMA] { "has_deadlock": boolean, "cycles": [ { "path": ["[STEP_NAME]", ...], "description": "[CYCLE_DESCRIPTION]" } ] }
Watch for
- False positives on workflows with conditional branches that never form real cycles
- Missing transitive dependencies when workflows chain across multiple files
- Overly broad cycle descriptions that don't help the operator locate the conflict

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us