@@@snippet_name@@@ must be published after its dependencies. Publishing a parent template before its referenced snippets exist in the workspace fails validation.
This guide explains the snippet dependency model, the required publish order, and a multi-pass workflow for CI pipelines and MCP agents.
Snippet dependency model
A snippet is a completion prompt template referenced from another template using@@@ syntax. Snippets can reference other snippets, forming a dependency graph.
See Snippets for the three reference formats:
- By template name:
@@@template_name@@@— uses the latest version of the referenced template. - By version number:
@@@template_name@version_number:{number}@@@— pins a specific version. - By release label:
@@@template_name@label:{label_name}@@@— uses the version with that label.
@@@ tags with snippet content.
Only completion templates can be used as snippets. See Snippets for details.
Required publish ordering
Publish templates in dependency-first order: leaf snippets with no snippet references first, then templates that depend on them, and finally parent prompts that compose multiple snippets.Example dependency graph
| Template | Content includes | Depends on |
|---|---|---|
base-instructions | Standalone completion text | — |
tone-guide | @@@base-instructions@@@ plus tone rules | base-instructions |
customer-support | @@@tone-guide@@@ and @@@base-instructions@@@ | tone-guide, base-instructions |
base-instructionstone-guidecustomer-support
customer-support or tone-guide before base-instructions fails because the referenced snippet does not exist yet.
Multi-pass publish workflow
CI pipelines and MCP agents that bulk-publish templates should resolve dependencies before publishing. Use a multi-pass approach when templates reference each other.Step 1: Discover snippet references
Fetch each template with snippet resolution disabled so@@@ references stay in the raw content:
snippets array listing resolved snippet references when resolve_snippets=true.
Step 2: Build and sort the dependency graph
For each template you plan to publish, collect its snippet dependencies and topologically sort so dependencies come first. Templates with no snippet references are leaves and publish first. If template A references template B, and both are in your publish batch, B must appear before A in the sorted list.Step 3: Publish in order
Publish each template after its dependencies exist in the workspace.Step 4: Retry on failure (multi-pass)
If a publish fails because a dependency is not yet available, skip that template and retry it on the next pass after its dependencies are published. Stop when all templates succeed or a pass makes no progress (which indicates a circular reference or a missing external dependency).MCP agent workflow
When using the PromptLayer MCP server, the same dependency-first ordering applies topublish-prompt-template.
Recommended tool sequence:
list-prompt-templates— list templates in the workspace. Useis_snippet=trueto filter snippets.get-prompt-template-raw— fetch raw content with unresolved@@@references to discover dependencies.get-snippet-usage— find which prompts reference a snippet (useful for impact analysis before republishing).publish-prompt-template— publish templates in dependency-first order.
@@@ references from raw template content, sort templates topologically, and publish leaf snippets before parents. If a publish fails, retry remaining templates on subsequent passes.
CI/CD and GitOps
When syncing prompts from a Git repository to PromptLayer, publish snippet dependencies before parent templates. See Deployment Strategies for CI/CD patterns. A typical GitOps pipeline should:- Parse all prompt files in the repository.
- Extract
@@@snippet references from each file. - Topologically sort templates by dependency.
- Publish in sorted order, retrying failed templates on subsequent passes.
Publish errors
When a parent template references a snippet that does not exist in the workspace, Publish Prompt Template returns a 422 Validation Error. To debug:- Confirm the referenced snippet name matches exactly (snippet names are case-sensitive).
- Verify the dependency was published in an earlier pass.
- Use Get Snippet Usage to confirm whether a snippet exists and which prompts reference it.
- Fetch the parent template with
resolve_snippets=falseto inspect unresolved@@@references.
Related
- Snippets — snippet syntax, rendering, and restrictions
- Publish Prompt Template — REST API for programmatic publishing
- Get Prompt Template (Raw) — inspect unresolved snippet references
- Get Snippet Usage — find prompts that reference a snippet
- MCP & Skills — MCP tools for prompt publishing
- Deployment Strategies — CI/CD and GitOps patterns

