What Are Patterns in Fabric? A Technical Guide to AI Prompt Automation

Patterns in Fabric are reusable, file-based AI prompt specifications that encapsulate complete language model interactions through a structured system.md file, enabling execution via CLI, REST API, or web interface.

Patterns are the modular building blocks of the danielmiessler/fabric open-source framework, designed to standardize and automate complex interactions with large language models. Each Pattern acts as a self-contained workflow defined by markdown files stored in directory structures, allowing users to declare "what the AI should do" and reuse that logic consistently across multiple interfaces.

Anatomy of a Fabric Pattern

The Three Required Sections

Every Pattern directory under data/patterns/ (or ~/.config/fabric/patterns/ for custom Patterns) must contain a system.md file with three logical sections:

  1. IDENTITY & PURPOSE – Defines the role the model should assume (e.g., expert summarizer, code reviewer).
  2. STEPS – The explicit sequence of instructions the model must follow to process input.
  3. OUTPUT INSTRUCTIONS – Specifications for the expected format, structure, and constraints of the result.

File Structure and Optional Components

In addition to the mandatory system.md, Patterns support:

  • user.md – Optional context file for additional prompt content.
  • Variable placeholders – Dynamic values interpolated at runtime via --var key=value flags or JSON payloads.

How Fabric Executes Patterns

When invoked, Fabric automatically prepends the system.md contents as a system message. The framework optionally interpolates user-provided variables into the prompt template, sends the composite request to the selected model, and streams the output back to the user.

According to the source code in internal/server/patterns.go, the ApplyPattern endpoint handles this execution flow by combining the Pattern's system definition with runtime inputs and variables.

Running Patterns Across Interfaces

Command Line Interface

The CLI provides the most direct access to Patterns using the --pattern flag:

fabric --pattern summarize --input "https://example.com/article"

REST API

The Go backend exposes Pattern execution via HTTP endpoints. The ApplyPattern function processes POST requests to /patterns/{name}/apply:

curl -X POST http://localhost:8080/patterns/translate/apply \
  -H "Content-Type: application/json" \
  -d '{
        "input": "Hola, ¿cómo estás?",
        "variables": {"target_language": "en"}
      }'

Reference: [internal/server/patterns.go lines 71-84](https://github.com/danielmiessler/fabric/blob/main/internal/server/patterns.go#L71-L84)

Web UI and Python Interface

The Streamlit-based interface discovers Patterns by scanning the filesystem. In scripts/python_ui/streamlit.py, the get_patterns() function enumerates available Patterns:

def get_patterns():
    """Get the list of available patterns from the specified directory."""
    if not os.path.exists(pattern_dir):
        st.error(f"Pattern directory not found: {pattern_dir}")
        return []
    patterns = [
        item for item in os.listdir(pattern_dir)
        if os.path.isdir(os.path.join(pattern_dir, item))
    ]
    return patterns

Creating and Validating Custom Patterns

Users can extend Fabric by creating custom Patterns in their local configuration directory. The create_pattern function in scripts/python_ui/streamlit.py demonstrates the validation and initialization workflow:

def create_pattern(pattern_name: str, content: Optional[str] = None) -> Tuple[bool, str]:
    # … validation and directory creation …

    system_file = os.path.join(new_pattern_path, "system.md")
    with open(system_file, "w") as f:
        f.write(content or "# IDENTITY and PURPOSE\n\n# STEPS\n\n# OUTPUT\n")

    # … validation …

    return True, f"Pattern '{pattern_name}' created successfully."

Fabric validates Pattern structure using the validate_pattern utility, which checks for the presence of required sections (# IDENTITY, # STEPS, # OUTPUT).

Chaining Patterns for Complex Workflows

Pattern Chains enable sequential processing where the output of one Pattern becomes the input of the next. The execute_pattern_chain function in scripts/python_ui/streamlit.py implements this by iterating through a sequence list:

def execute_pattern_chain(patterns_sequence: List[str], initial_input: str) -> Dict:
    current_input = initial_input
    for pattern in patterns_sequence:
        cmd = ["fabric", "--pattern", pattern]
        result = run(cmd, input=current_input, capture_output=True, text=True, check=True)
        current_input = result.stdout.strip()   # output becomes next input

    return {"final_output": current_input}

This architecture supports multi-stage AI pipelines such as extract-then-summarize or translate-then-analyze workflows without intermediate manual steps.

Summary

  • Patterns are file-based prompt specifications stored in data/patterns/<name>/ with a mandatory system.md containing IDENTITY, STEPS, and OUTPUT sections.
  • Multi-interface execution supports CLI (--pattern), REST API (POST /patterns/{name}/apply), and Web UI interactions.
  • Variable substitution allows dynamic runtime customization via CLI flags or JSON payloads.
  • Validation ensures structure through validate_pattern checks for required markdown headers.
  • Pattern Chains enable sequential automation by piping outputs between consecutive Patterns.

Frequently Asked Questions

Where are Fabric Patterns stored?

Built-in Patterns reside in the data/patterns/ directory of the repository, while user-created custom Patterns are stored in ~/.config/fabric/patterns/. The system scans both locations to populate the available Pattern list in the UI and CLI.

Can I pass custom variables to a Pattern?

Yes. Variables are interpolated into the system.md template at runtime. Supply them via the CLI using --var key=value syntax, or include a variables object in the JSON body when calling the REST API endpoint.

How do I create a new Pattern for personal use?

Create a new directory in ~/.config/fabric/patterns/ containing a system.md file with the three required sections (IDENTITY & PURPOSE, STEPS, OUTPUT INSTRUCTIONS). Optionally add a user.md file for additional context. The Pattern will automatically appear in the Fabric UI and CLI listings.

What is Pattern validation in Fabric?

The validate_pattern function checks that your system.md contains the mandatory headers (# IDENTITY, # STEPS, # OUTPUT). This ensures consistency across the ecosystem and prevents runtime errors from malformed prompt specifications.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →