square-terminalPromptDSL Specification

PromptDSL (Prompt Domain-Specific Language) is the foundational schema language of PromptHub. It allows developers to define prompts not as ad hoc text strings, but as formally structured, machine-readable semantic contracts. Each PromptDSL module encapsulates a unit of prompt logic, including its inputs, parameters, dependencies, template structure, and outputs.

PromptDSL Visual Example

The diagram below illustrates how a PromptDSL module transforms from a raw prompt into a structured, executable asset:

┌─────────────────────────────────────────────────────────────────────────────┐
│                                                                             │
│  【TRADITIONAL PROMPT】                                                      │
│  Analyze the following text and extract key people, places, and events      │
│  in JSON format                                                             │
│                                                                             │
│                              │                                              │
│                              │  STANDARDIZATION                             │
│                              ▼                                              │
│                                                                             │
│  【PROMPTDSL STRUCTURED MODULE】                                             │
│  ┌─────────────────────────────────────────────────────────────┐            │
│  │ {                                                           │            │
│  │   "id": "entity_extractor_v1.2",                           │            │
│  │   "name": "Entity Extractor",                              │            │
│  │   "description": "Extracts entities from text",            │            │
│  │   "author": "0x7F9a...3B2e",                               │            │
│  │   "version": "1.2.0",                                      │            │
│  │   "inputs": {                                              │            │
│  │     "text": { "type": "string", "required": true },        │            │
│  │     "entity_types": {                                      │            │
│  │       "type": "array",                                     │            │
│  │       "default": ["person", "location", "event"]           │            │
│  │     }                                                      │            │
│  │   },                                                       │            │
│  │   "template": "Analyze the following text and extract      │            │
│  │               {{entity_types}} entities. Return in JSON:   │            │
│  │               {{text}}",                                   │            │
│  │   "output_schema": {                                       │            │
│  │     "entities": {                                          │            │
│  │       "type": "object",                                    │            │
│  │       "properties": { ... }                                │            │
│  │     }                                                      │            │
│  │   },                                                       │            │
│  │   "dependencies": ["text_cleaner_v1"]                      │            │
│  │ }                                                          │            │
│  └─────────────────────────────────────────────────────────────┘            │
│                                                                             │
│                                                                             │
│                              │                                              │
│                              │  ON-CHAIN REGISTRATION                       │
│                              ▼                                              │
│                                                                             │
│  【ON-CHAIN ASSET】                                                         │
│  ┌─────────────────────────────────────────────────────────────┐            │
│  │ PromptVault                                                 │            │
│  │ • Module ID: entity_extractor_v1.2                          │            │
│  │ • IPFS Link: ipfs://Qm...                                   │            │
│  │ • Creator: 0x7F9a...3B2e                                    │            │
│  │ • License: CC-BY-SA                                         │            │
│  │ • Usage Fee: 0.01 $PHUB/call                                │            │
│  │ • Dependency Tree: [text_cleaner_v1]                        │            │
│  │ • Version History: v1.0 -> v1.1 -> v1.2                     │            │
│  └─────────────────────────────────────────────────────────────┘            │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

PromptDSL is designed to be:

  • Deterministic: each prompt version yields reproducible results

  • Composable: prompts can embed or call other prompts

  • Modular: prompts can be assembled into larger DAG workflows

  • Tokenizable: each prompt can be bound to ownership, licensing, and economics

1. PromptDSL Structure

A PromptDSL module is defined using a JSON-based schema with the following required and optional fields:

Field descriptions:

Field
Type
Required
Description

id

String

Yes

Unique identifier for the prompt module

name

String

Yes

Human-readable name

description

String

Yes

Brief explanation of functionality

version

String

Yes

Semantic version (follows semver)

author

String

Yes

Creator's wallet address

license

String

Yes

License identifier (e.g., "MIT", "CC-BY-SA-4.0")

inputs

Object

Yes

Schema of input parameters

template

String

Yes

Template with variable placeholders

output_schema

Object

Yes

JSON Schema for expected output

dependencies

Array

No

Other prompt modules required

execution_settings

Object

No

Model-specific parameters

tags

Array

No

Categorical tags for discovery

models

Array

No

Compatible model providers

2. Input Parameter Specification

Each input parameter must define its data type and can include additional constraints:

3. Template Syntax and Context Injection

PromptDSL supports a rich templating syntax for parameter injection:

This powerful templating system allows for dynamic content generation based on input parameters and conditional logic.

4. Embedding & Composition

PromptDSL supports modular composition through direct module references. This enables developers to create reusable utility prompts and compose complex chains from simple modules:

When executed, each referenced module's output becomes available to subsequent template sections, allowing for multi-step processing within a single prompt definition.

5. PromptDSL Validation & Compilation Process

The PromptDSL compilation pipeline consists of several stages:

  1. Schema Validation: The DSL document is validated against the PromptDSL JSON Schema to ensure all required fields are present and correctly formatted.

  2. Dependency Resolution: All referenced modules are resolved, and a dependency graph is constructed to ensure all requirements are satisfied.

  3. Template Parsing: The template string is parsed into an abstract syntax tree (AST) that identifies all variable references, conditionals, loops, and module invocations.

  4. Output Schema Validation: The output schema is checked for validity against JSON Schema standards.

  5. Optimization: The compiled template is optimized for efficient execution, including pre-computation of static sections and caching of repeated expressions.

  6. Serialization: The validated and optimized prompt module is serialized to a canonical format suitable for on-chain storage.

  7. IPFS Pinning: The complete PromptDSL definition is pinned to IPFS for decentralized storage and content-addressed retrieval.

  8. On-Chain Registration: A reference to the IPFS content hash, along with key metadata, is registered in PromptVault for verification and discovery.

6. Example Use Cases for PromptDSL

Enterprise Document Processing Pipeline:

Agent Reasoning Module:

Multi-Modal Prompt:

PromptDSL turns prompt authoring into software engineering—structured, composable, testable, and deployable across decentralized AI infrastructures.

Last updated