Story based framing

From BbgnsurfTech/claude-skills-collection · View interactive version

Story based framing is an AI agent skill from the GitHub repository BbgnsurfTech/claude-skills-collection. This skill should be used when describing patterns or anti-patterns for detection by LLM agents across any domain (code analysis, business processes, security audits, UX design, data quality, medical diagnosis, etc.). Uses narrative storytelling structure ("The Promise" → "The Betrayal" → "The Conse

How to use this skill

Skill file

Story-Based Framing for Pattern Detection

Overview

Story-based framing uses narrative structure to describe patterns and anti-patterns across any domain, enabling LLM agents to identify them 70% faster than traditional approaches (checklists, formal specifications, or symptom-based descriptions). Experimental evidence from code analysis shows narrative descriptions requiring only 3 search steps versus 10 steps for refactoring-style descriptions.

The technique structures pattern descriptions as a causal story that mirrors the investigation thought process, frontloading the most distinctive criteria to eliminate false positives early. This approach is domain-independent - it works for code analysis, business process audits, security reviews, UX analysis, data quality checks, medical diagnosis, and any systematic pattern detection task.

When to Use This Skill

Use story-based framing when:

Applies to any domain where patterns need to be detected:

Core Narrative Structure

Story-based pattern descriptions follow a four-act structure that establishes causal relationships:

flowchart TD
    Start([Pattern Detection Task]) --> Act1[Act 1: The Promise<br/>What the system claims to do<br/>or appears correct]
    Act1 --> Act2[Act 2: The Betrayal<br/>Where reality violates the promise]
    Act2 --> Act3[Act 3: The Consequences<br/>Observable symptoms from violation]
    Act3 --> Act4[Act 4: The Source<br/>Root cause explanation]
    Act4 --> Fix[The Fix<br/>Resolution approach]
    Fix --> End([Pattern Documented])

    Act1 -.->|Filters 90% non-matches| Search1[Search Impact: Most distinctive criterion]
    Act2 -.->|Narrows to true matches| Search2[Search Impact: Second distinctive criterion]
    Act3 -.->|Validates matches| Search3[Search Impact: Verification criteria]
    Act4 -.->|Informs fixes| Search4[Search Impact: Understand if isolated or systemic]

Act 1: The Promise

Describe what the system/process/code _claims_ to do or _appears_ to implement correctly at first glance.

Purpose: Establish the initial correct-looking state that creates false confidence.

Examples across domains:

Search Impact: Identifies the most distinctive structural criterion that filters 90% of non-matches immediately.

Act 2: The Betrayal

Reveal where the implementation/reality _violates_ the promise.

Purpose: Show the specific point where correctness breaks down.

Examples across domains:

Search Impact: Provides the second most distinctive criterion that narrows remaining candidates to true matches.

Act 3: The Consequences

Describe the observable _symptoms_ that result from the violation.

Purpose: Provide verification criteria that confirm the pattern is present.

Examples across domains:

Search Impact: Enables agents to validate matches and distinguish true positives from similar-looking but different patterns.

Act 4: The Source

Explain _why_ the pattern exists - the root cause or architectural decision that led to this.

Purpose: Provide context that explains origin and suggests fixes.

Examples across domains:

Search Impact: Helps agents understand whether the pattern is isolated or systemic, informing fix strategies.

Narrative Template

Use this template when creating pattern descriptions for any domain:

# Pattern: {Memorable Descriptive Name}

## The Story

### Act 1: The Promise

{What the system/process/code claims to do or appears to implement correctly}

**Observable characteristics**: {What you would see that makes this look correct initially}

### Act 2: The Betrayal

{Where the reality violates the promise}

**The breaking point**: {Specific moment/location/condition where correctness fails}

### Act 3: The Consequences

{Observable symptoms that result from the violation}

**Symptoms**:

- {Symptom 1}
- {Symptom 2}
- {Symptom 3}

### Act 4: The Source

{Why the pattern exists - root cause}

**Origin**: {Architectural decision, legacy constraint, incentive misalignment, etc.}

## The Fix

{Brief description of the correct solution}

**Resolution approach**: {How to address the root cause}

Pattern Description Effectiveness Data

Experimental validation from code analysis domain (see resources/code-analysis/experiment_results.md):

| Style | Steps | Efficiency |

| --------------------------- | ----- | ---------------------- |

| Narrative (story-based) | 3 | ⭐⭐⭐⭐⭐ Best (100%) |

| XML structured | 4 | ⭐⭐⭐⭐ (80%) |

| Checklist | 7 | ⭐⭐⭐ (43%) |

| Formal mathematical | 7 | ⭐⭐⭐ (43%) |

| Refactoring (symptom-based) | 10 | ⭐⭐ Slowest (30%) |

Key Insight: Narrative framing provides causal flow that matches investigation intuition, while symptom-based approaches require validating each "red flag" separately. This finding is domain-independent - the cognitive benefit of causal storytelling applies to any pattern detection task.

Design Principles

Frontload Distinctive Criteria

Place the most unique, identifying characteristics in Act 1 and Act 2. These should eliminate 90%+ of false positives immediately.

Poor ordering (generic symptoms first):

  1. "Has error messages"
  2. "Has workarounds"
  3. "Violates specification X"

Good ordering (distinctive structure first):

  1. "Claims to implement specification X"
  2. "But actually violates constraint Y"
  3. "Resulting in error messages and workarounds"

Use Causal Language

Connect each act with causal transitions that explain _why_ the next act follows.

Weak transitions:

Strong transitions:

Provide Domain-Appropriate Examples

Include realistic examples for the target domain, using varied names/scenarios to avoid agents matching on specific identifiers.

Vary details across examples to ensure structural pattern matching:

This prevents agents from searching for literal names instead of structural patterns.

Make It Memorable

Choose pattern names that evoke the core problem, appropriate to the domain:

Comparison with Other Approaches

vs. Checklists

Checklist: "□ Violates spec □ Has workarounds □ Causes errors"

Story: "Promise: Implements spec X → Betrayal: Violates constraint Y"

vs. Formal Specifications

Formal: "∃ system S such that: S claims property P and ∀ inputs I: S violates P(I)"

Story: "System promises property P but violates it under condition I"

vs. Symptom-Based (Red Flags)

Symptom: "Red Flag #1: Errors occur, Red Flag #2: Workarounds exist, Red Flag #3: Users complain"

Story: "Promise violation causes errors and workarounds because..."

Practical Usage

Pattern Detection Workflow

flowchart TD
    Start([Receive Detection Task]) --> Check1{Does candidate match<br/>Act 1: The Promise?}
    Check1 -->|No - 90% filtered| Reject1[Discard as non-match]
    Check1 -->|Yes| Check2{Does candidate show<br/>Act 2: The Betrayal?}
    Check2 -->|No| Reject2[Discard as false positive]
    Check2 -->|Yes| Check3{Are symptoms from<br/>Act 3: The Consequences<br/>present?}
    Check3 -->|No| Reject3[Discard - similar but different pattern]
    Check3 -->|Yes| Validate[Validate: Does Act 4: The Source<br/>explain the root cause?]
    Validate -->|Yes| Report[Report Match with Evidence]
    Validate -->|No| Investigate[Further Investigation Needed]

    Report --> End([Pattern Instance Documented])
    Investigate --> End

    Reject1 --> End
    Reject2 --> End
    Reject3 --> End

    style Check1 fill:#e1f5ff
    style Check2 fill:#fff4e1
    style Check3 fill:#ffe1e1
    style Validate fill:#e1ffe1
    style Report fill:#90EE90

For Automated Detection

When creating prompts for LLM-based detection agents:

Search for instances of "{Pattern Name}" in {domain}:

**The Promise**: {What appears correct initially} **The Betrayal**: {Where reality violates the promise} **The Consequences**: {Observable symptoms} **The Source**: {Why this exists}

Report: {identifier}, {location}, evidence for each act.

For Documentation

When documenting anti-patterns or failure modes:

  1. Use the narrative template from assets/narrative_template.md
  2. Fill in domain-specific examples
  3. Include the fix as Act 5 (optional)
  4. Store in appropriate documentation location

For Sub-Agent Delegation

When delegating pattern-finding tasks to sub-agents:

Task(
    subagent_type="Explore",
    description="Find {pattern name} in {domain}",
    prompt="""
    Locate instances matching this pattern:

    Act 1 (The Promise): {What should be true}
    Act 2 (The Betrayal): {What actually happens}
    Act 3 (The Consequences): {Observable symptoms}
    Act 4 (The Source): {Why this exists}

    Report all matches with evidence.
    """
)

Advanced Techniques

Multi-Pattern Stories

For related patterns, create a shared narrative universe:

Pattern Family: "Communication Breakdown"

Each uses similar four-act structure but different specific betrayals.

Nested Narratives

For complex patterns with sub-patterns:

Main Story: "The Broken Promise"

Comparative Narratives

For patterns with subtle differences:

Pattern A: "The False Promise" (claims X but delivers Y) Pattern B: "The Partial Promise" (claims X and delivers some X but not all)

Key Difference: Act 2 betrayal point - complete violation vs. partial delivery.

Domain-Specific Use Cases

Code Analysis

Complete use case with experimental validation, pattern examples, and practical applications.

See: resources/code-analysis/ directory for:

Business Process Analysis

[Create similar use case directory when needed]

Security Auditing

[Create similar use case directory when needed]

UX/Design Review

[Create similar use case directory when needed]

Resources

assets/

resources/code-analysis/

Future Resources

Additional domain-specific use cases can be added as needed to demonstrate versatility across domains.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.