ArtificialGuyBR

Home / Blog / Prompting and control

Wildcards & Dynamic Prompts: A1111, Forge, Fooocus

Wildcard syntax and dynamic prompt generation in A1111, Forge, and Fooocus

3 sources cited Prompting and control

Wildcards & Dynamic Prompts: A1111, Forge, Fooocus

TL;DR: Wildcards and dynamic prompts let Stable Diffusion users insert random or pre-defined values into prompts using __filename__ syntax. This article covers syntax across A1111, Forge, and Fooocus, generation modes, and common fixes.

What Are Wildcards?

A wildcard is a placeholder token like __filename__ that expands to a random value from a .txt file at generation time. Instead of writing "a picture of a dog," you write __animal__ and the tool picks one line from the file. This lets you explore many prompt variations without manually rewriting each one.


Syntax Comparison Across Platforms

Core Wildcard Syntax

All three platforms use the same basic token structure:

__filename__

The token references a .txt file containing one value per line. During generation, the tool reads the file, picks one line, and inserts it into the prompt.

A1111 Dynamic Prompts uses this as its primary mechanism (https://github.com/adieyal/sd-dynamic-prompts). The extension reads files from extensions/sd-dynamic-prompts/wildcards and substitutes values randomly or combinatorially.

Fooocus uses identical syntax (https://github.com/lllyasviel/Fooocus). Users place .txt files in the wildcards/ directory and reference them the same way in prompts.

Forge inherits from the A1111 codebase but does not include a native wildcard extension (https://github.com/lllyasviel/stable-diffusion-webui-forge). Users must install the sd-dynamic-prompts extension separately to get full wildcard support.

Variant Syntax

A1111 and Forge use curly braces with pipe separators for inline random choices:

{option1|option2|option3}

For selecting multiple values from a list:

{2$$chocolate|vanilla|strawberry}

The number followed by $$ tells the tool to pick that many unique options from the list.

Fooocus Variants

Fooocus supports a simpler variant system. It reads predefined lists and applies them based on configuration, but its variant syntax is less flexible than A1111's {}|{} structure.


Generation Modes Explained

Combinatorial Mode (A1111)

Combinatorial generation lists every possible combination of options instead of sampling one random result. For a template like {a|b} {c|d}, it produces:

When wildcards are present, it adds one prompt per wildcard value. This can explode quickly with multiple wildcards, so A1111 includes a Max Generations slider to cap output.

Random Mode (All Platforms)

Random mode picks one option per position per prompt. The same template produces only one result per generation:

a c

or

b d

You can run it multiple times to get variety, but with no guarantee of covering all combinations.

Key Difference

ModeWhat it doesUse caseSource
CombinatorialProduces all possible combinationsExhaustive testing, dataset generationsd-dynamic-prompts/README.md
RandomPicks one random combination per generationCreative exploration, one-off imagessd-dynamic-prompts/README.md

Building Reusable Wildcard Files

A1111 Directory Structure

extensions/sd-dynamic-prompts/wildcards/
├── seasons.txt
├── artists/
│   ├── famous.txt
│   └── contemporary.txt
└── styles/
    ├── impressionist.txt
    └── surrealist.txt

Fooocus Directory Structure

wildcards/
├── animal.txt
├── artist.txt
├── color.txt
├── color_flower.txt
├── extended-color.txt
├── flower.txt
└── nationality.txt

Fooocus ships seven default files. You can add your own by creating new .txt files in this directory.

Advanced A1111 Features

Glob matching: Use __artists*__ to match all files starting with "artists" across multiple files.

Recursive matching: Use __styles/**/*__ to match files in any nested subdirectory.

Nesting: Place one wildcard token inside another wildcard file. If countries.txt contains __africa__, it will resolve recursively to the actual values in africa.txt.


Platform-Specific Considerations

A1111 Dynamic Prompts

A1111 has the most complete wildcard system. It supports:

The downside: combinatorial mode can generate thousands of prompts if you are not careful with the Max Generations limit.

Fooocus

Fooocus takes a simpler approach. It uses the same __filename__ syntax but provides fewer configuration options. It includes an offline GPT-2-based prompt processing engine that can help with prompt variety, but does not offer explicit combinatorial mode.

Forge

Forge is built on A1111 but does not include wildcard extensions by default. Users report that wildcards sometimes fail to resolve, showing the literal __token__ text instead. The most common fix is installing the sd-dynamic-prompts extension and ensuring files are in the correct directory.


Common Errors and Fixes

Wildcard returns literal __season__ text

Cause: The wildcard file is not in the correct directory, or the filename does not match the token used in the prompt.

Fix: Place the file in extensions/sd-dynamic-prompts/wildcards/ and verify the filename matches exactly. Paths must be absolute, not relative.

Duplicate wildcard values in output

Cause: Using the same wildcard twice in one prompt without deduplication.

Fix: Wrap in a variant: {2$$__flavours__} guarantees unique selections from the same file.

Too many images generated

Cause: Combinatorial mode is enabled with multiple wildcards, producing an exponential number of combinations.

Fix: Disable the combinatorial checkbox, or raise the Max Generations slider limit to cap output.

Batch count slider too low

Cause: The default A1111 batch-count maximum is 100, which is insufficient for large combinatorial sets.

Fix: Edit ui-config.json and change "txt2img/Batch count/maximum" to a higher value like 1000.


Learning Resources

Official Documentation

Internal Documentation

For deeper implementation details, see:

Troubleshooting

Common error messages:


Conclusion

Each platform handles wildcards differently. A1111 provides the most comprehensive feature set with combinatorial generation and advanced file matching. Fooocus offers a simpler, more streamlined experience but lacks combinatorial mode. Forge inherits A1111's architecture but requires manual extension installation for reliable wildcard support.

Choose the platform based on your needs:


FAQ

What is the difference between random and combinatorial mode in A1111?

Random mode picks one combination per generation. Combinatorial mode generates every possible combination from your template. Use random for creative exploration; use combinatorial when you need complete coverage of all options.

Where do I put wildcard files in Fooocus?

Place .txt files in the wildcards/ directory at the root of your Fooocus installation. The repository includes seven default files: animal.txt, artist.txt, color.txt, color_flower.txt, extended-color.txt, flower.txt, and nationality.txt.

Which syntax is shared between A1111, Forge, and Fooocus?

All three use double underscores for wildcards: __filename__. The A1111 Dynamic Prompts extension provides the full feature set; Fooocus uses the same token but with fewer options; Forge inherits from A1111 but needs the extension installed.

Can I nest wildcards inside other wildcards?

Yes. In A1111, you can place __wildcard__ tokens inside other wildcard files. If countries.txt contains __africa__, the system resolves it recursively to values from africa.txt. This supports complex hierarchical wildcard structures.

How do I make Fooocus exhaust every artist in a file?

Fooocus uses random selection by default, so you cannot guarantee all values are used in a single run. Create a comprehensive wildcard file listing all artists, then generate multiple images to increase coverage. Fooocus's GPT-2 prompt processing engine can help vary results.


Sources

JSON-LD Schema