Skip to main content

dap-prompt-dsl

Deterministic prompt compiler for the DAP (Deterministic Agent Pipeline) ecosystem. Takes a Jinja2 template plus a JSON context and emits a validated XML prompt — the wire format every DAP agent uses to talk to its runtime adapter.

Why this exists

DAP's core principle is "the prompt is code": every agent's behaviour is defined by a versioned prompt_template and a declared input_schema against PipelineState. To keep that principle intact, the prompt compiler must be:

  • Pure — same inputs always produce the same output. No hidden randomness, no time-dependent rendering, no network calls during render. The result is reproducible across machines and across time.
  • Sandboxed — agent templates come from end-user input via the dashboard. The compiler must not let a template author read the host filesystem or escape into the engine process.
  • Strict on shape — the rendered output is XML the runtime parses. Malformed or unsafe XML is rejected at compile time, not at the runtime adapter, so the failure mode is clean.

What's in here

Symbol Purpose
build_prompt(template, context) Single entry point. Renders the Jinja2 template under the supplied context, parses the result as XML, returns a BuildResult. Internally wires Jinja2's stock SandboxedEnvironment (via a private _make_sandbox() factory) to the rendering step.
BuildResult Dataclass describing the compiled prompt: xml, the rendered string; validation, a ValidationOutcome; plus metadata fields (role, agent_id, template_hash, ...).
PromptBuildError Raised when rendering or validation fails — wraps the underlying Jinja / XML / schema error with the offending template context.
validate_xml(xml: str) → ValidationOutcome Standalone XML validator (also in dap_prompt_dsl.validator). Parses with defusedxml.ElementTree under the hood, so XXE / billion-laughs / external-entity attacks are rejected; checks the <agent_prompt> envelope shape. Useful for linting a template's expected output without doing a full Jinja render.
PromptContextBase + role-specific subclasses (TestAuthorContext, ImplementerContext, VerifierContext) Pydantic models describing what each agent role gets passed into its template context.
RESERVED_METADATA_KEYS Set of keys the builder reserves for its own metadata (agent_id, template_hash, ...). Templates can't shadow these in their context.

Installation

Usually installed transitively via dap-cli:

pipx install dap-cli

Standalone (if you're embedding the prompt compiler in another tool — e.g. a linter that validates agent templates without running the engine):

pip install dap-prompt-dsl

Usage

from dap_prompt_dsl import build_prompt

result = build_prompt(
    template=(
        "<agent_prompt version=\"1\">"
        "<role>{{ role }}</role>"
        "<task>{{ task }}</task>"
        "</agent_prompt>"
    ),
    context={"role": "test_author", "task": "Write a unit test for issue #42."},
)

if not result.valid:
    raise ValueError(result.errors)

print(result.xml)
# <agent_prompt version="1"><role>test_author</role><task>Write a unit test for issue #42.</task></agent_prompt>

The engine calls build_prompt once per node execution as part of the LangGraph state machine. The same call also drives the dashboard's Render preview button on /agents/<id>/edit, so template authors can see the compiled XML without burning LLM tokens.

Security model

This package handles untrusted input — agent templates can be authored by any operator with is_active=True on the engine. Two layers of defense:

  • Jinja2 SandboxedEnvironment — blocks access to dunder methods (__class__, __mro__, ...), prevents traversal into Python builtins, refuses getattr on objects not registered as template-safe. Templates can render strings, numbers, lists, and dicts from the context; they can't open files, spawn subprocesses, or import modules.
  • defusedxml — XML parsing rejects XXE attacks (external entity injection), billion-laughs (entity expansion DoS), and DTD inclusion. The parser is strict-byte mode; embedded null bytes are rejected before parsing begins.

A successful build_prompt call means the XML is safe to log, safe to send to the runtime adapter, and free of injection vectors that the runtime might mis-parse. Adapters still validate the agent_prompt envelope themselves before handing off to the LLM — defence in depth.

Compatibility

  • Python 3.13+
  • Jinja2 3.1+, defusedxml 0.7+

See also

License

See the main repository for licensing details.

Metadata

Release files for dap-prompt-dsl 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dap-prompt-dsl 0.4.0
File Size Uploaded Provenance Actions
dap_prompt_dsl-0.4.0.tar.gz 7.7 kB With provenance Details for dap_prompt_dsl-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dap-prompt-dsl 0.4.0
File Interpreter ABI Platform Actions
dap_prompt_dsl-0.4.0-py3-none-any.whl Python 3 none any Details for dap_prompt_dsl-0.4.0-py3-none-any.whl

Total release size: 16.6 kB

Release files / dap_prompt_dsl-0.4.0.tar.gz

Download URL dap_prompt_dsl-0.4.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f1ad7cd9caca2dbe9e66673847a3ee3dccc352aaa85e6660dff2ef0d567dd774
BLAKE2b-256 checksum
How to use checksums
d3e21eaa5318cdfa430a2250641ccf40a59228a659b750d4b0e4641c0f199aba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / dap_prompt_dsl-0.4.0-py3-none-any.whl

Download URL dap_prompt_dsl-0.4.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7ebad3827b98bb2b8e77eb09caa74efbaa2c9128c06bbfcae4ba2204a757ef3
BLAKE2b-256 checksum
How to use checksums
65d65f73cb1646a30c5a7350fb8587337992945c086d1e25489343f89828a180
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for dap-prompt-dsl 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dap_prompt_dsl-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page