PDDL: describe the task, then validate a proposed plan
PDDL 规划语言
Read a small explicit language fragment, reject unsupported features and distinguish syntax errors, failed steps and unmet goals.
pddlA plan needs a model that another program can read
A parcel must be inspected and sealed. Inspection needs an open parcel; sealing closes it. The sequence inspect → seal succeeds. Seal → inspect does not. A planning language lets a modeller state those rules independently of the algorithm that searches for an action sequence.
PDDL, the Planning Domain Definition Language, separates a reusable domain from a particular problem. The domain declares predicates and actions. The problem selects the domain, supplies initial facts and states a goal. A planner searches under those declarations; a validator checks a supplied plan. Neither learns the intended meaning of “inspect” from its English spelling.
The PDDL 1.2 manual was prepared by the AIPS-98 Planning Competition Committee, with Drew McDermott as chair, and dated October 1998. Its purpose included making problems comparable across planners. It already described more than elementary STRIPS actions; one should not mistake a parser’s supported fragment for the entire language. Original manual, title page and §2.
Separate syntax, supported features and successful execution
PDDL uses parenthesized forms. A name such as open identifies a predicate; (open) is a zero-argument atom. Parameterized forms such as (at ?parcel ?place) are also part of PDDL, but outside this chapter’s small reader. :requirements declares language features a model needs; declaring a feature does not make an incompatible planner support it. Names are case-insensitive, and semicolon comments extend to the next newline. Manual, printed pp2–6.
Here is the deliberately narrow contract used by the complete program:
| Accepted | Explicitly outside this reader |
|---|---|
One domain and one problem; :strips or omitted requirements | Other requirements, objects, types and constants |
Zero-argument predicates and actions with :parameters () | Variables, argument lists and grounding |
A positive atom or a flat and in preconditions and goals | Negative preconditions/goals, nested formulas and quantifiers |
Positive effects and not of an atom as a delete effect | Conditional, numeric, durative and nondeterministic effects |
| Positive initial facts; omitted facts are false | Unknown initial facts and sensing |
This restriction is local to the teaching reader, not a claim that the excluded constructs are invalid PDDL. Unknown sections and unsupported syntax raise ValueError; they are never silently discarded. A positive and negative effect on the same atom is also rejected by this interface.
For the accepted fragment, initial facts give a complete Boolean state. Preconditions are checked before an action, then delete effects remove facts and add effects establish facts. Unmentioned facts persist:
The last condition checks the goal only after the supplied sequence finishes. This is a sequential deterministic model. A delete expression (not (open)) changes the state; it is not a request to prove classical negation from an incomplete knowledge base. STRIPS develops the transition model and backward plan search in more detail.
There are three separate outcomes to diagnose. Malformed text, unsupported features or an unknown name raise a loading/interface error. A known action with an unsatisfied precondition produces inapplicable at a numbered step. A fully executable sequence may still finish with goal-not-met. Only valid establishes that this particular sequence meets the supplied goal in this model; it does not establish shortestness or real-world success.
Read declarations, then check each proposed step
The parser first builds nested lists using an explicit stack. The semantic loader then checks document headers, domain references, allowed fields, predicate declarations, action names and formula shapes. Repeated sections, duplicate declarations and undeclared atoms are rejected. The field order may vary after the required document header. This reader requires all three action fields, even though broader PDDL grammars can allow omissions.
The returned model contains normalized immutable fact sets and an action dictionary. Treat it as the loader’s output; validate does not revalidate arbitrary hand-built or subsequently edited model dictionaries. Its plan argument is a list or tuple of action-name strings. It is not a parser for temporal plan files or parenthesized plan text. All plan names are checked before any action executes, so an undeclared name late in a plan raises an error even when an earlier known action would have failed.
Successful execution records every state. An inapplicable action leaves the last recorded state unchanged and reports its missing preconditions. The step number starts at one; final results report the number of completed actions. An empty plan can be valid when the goal already holds.
# Python 3.10+; an explicit zero-argument, positive-STRIPS PDDL subset.
import re
def parse(text):
if type(text) is not str:
raise ValueError('PDDL input must be text')
text = re.sub(r';[^\n]*', ' ', text).lower()
roots, stack = [], []
for token in re.findall(r'\(|\)|[^\s()]+', text):
if token == '(':
node = []
(stack[-1] if stack else roots).append(node)
stack.append(node)
elif token == ')':
if not stack:
raise ValueError('unmatched closing parenthesis')
stack.pop()
elif stack:
stack[-1].append(token)
else:
raise ValueError('a document must contain one parenthesized form')
if stack or len(roots) != 1:
raise ValueError('unclosed or multiple top-level forms')
return roots[0]
def identifier(value):
if type(value) is not str or not re.fullmatch(r'[a-z][a-z0-9_-]*', value):
raise ValueError('invalid identifier')
return value
def header(text, category):
form = parse(text)
if len(form) < 2 or form[0] != 'define':
raise ValueError('expected define')
h = form[1]
if type(h) is not list or len(h) != 2 or h[0] != category:
raise ValueError('wrong document header')
return identifier(h[1]), form[2:]
def sections(rows, allowed):
result = {}
for row in rows:
if type(row) is not list or not row or type(row[0]) is not str:
raise ValueError('expected a named section')
if row[0] not in allowed or row[0] in result:
raise ValueError('unsupported or repeated section')
result[row[0]] = row[1:]
return result
def one(values):
if len(values) != 1:
raise ValueError('expected exactly one value')
return values[0]
def atom(form, predicates):
if type(form) is not list or len(form) != 1:
raise ValueError('only zero-argument atoms are supported')
p = identifier(form[0])
if p not in predicates:
raise ValueError('undeclared predicate')
return p
def literals(form, predicates, effects=False):
terms = form[1:] if type(form) is list and form and form[0] == 'and' else [form]
positive, negative = set(), set()
for term in terms:
if type(term) is list and len(term) == 2 and term[0] == 'not' and effects:
negative.add(atom(term[1], predicates))
else:
positive.add(atom(term, predicates))
if positive & negative:
raise ValueError('opposing effects are outside this subset')
return frozenset(positive), frozenset(negative)
def load(domain_text, problem_text):
domain, rows = header(domain_text, 'domain')
action_rows = [r for r in rows if type(r) is list and r and r[0] == ':action']
other = [r for r in rows if not (type(r) is list and r and r[0] == ':action')]
fields = sections(other, {':requirements', ':predicates'})
if fields.get(':requirements', [':strips']) != [':strips']:
raise ValueError('only :strips is supported')
if ':predicates' in fields and not fields[':predicates']:
raise ValueError('omit an empty predicates section')
predicates = []
for form in fields.get(':predicates', []):
if type(form) is not list or len(form) != 1:
raise ValueError('declare zero-argument predicates')
predicates.append(identifier(form[0]))
if len(set(predicates)) != len(predicates) or {'and', 'not'} & set(predicates):
raise ValueError('duplicate or reserved predicate')
predicates = frozenset(predicates)
actions = {}
for row in action_rows:
if len(row) < 2 or (len(row)-2) % 2:
raise ValueError('action needs key/value pairs')
key = identifier(row[1])
if key in actions:
raise ValueError('duplicate action')
f = sections([[row[i], row[i+1]] for i in range(2, len(row), 2)],
{':parameters', ':precondition', ':effect'})
if set(f) != {':parameters', ':precondition', ':effect'} or one(f[':parameters']) != []:
raise ValueError('supply all three action fields and empty parameters')
pre, _ = literals(one(f[':precondition']), predicates)
add, delete = literals(one(f[':effect']), predicates, effects=True)
actions[key] = (pre, add, delete)
problem, rows = header(problem_text, 'problem')
fields = sections(rows, {':domain', ':init', ':goal'})
if set(fields) != {':domain', ':init', ':goal'} or one(fields[':domain']) != domain:
raise ValueError('problem fields or domain reference do not match')
initial = frozenset(atom(f, predicates) for f in fields[':init'])
goal, _ = literals(one(fields[':goal']), predicates)
return dict(domain=domain, problem=problem, predicates=predicates,
actions=actions, initial=initial, goal=goal)
def validate(model, plan):
# plan is an API list of action names, not a parser for temporal plan files.
if type(plan) not in (list, tuple) or any(type(a) is not str for a in plan):
raise ValueError('plan must be a list or tuple of action names')
names = tuple(identifier(a.lower()) for a in plan)
if any(a not in model['actions'] for a in names):
raise ValueError('plan names an undeclared action')
state = model['initial']
history = [tuple(sorted(state))]
for step, key in enumerate(names, 1):
pre, add, delete = model['actions'][key]
if not pre <= state:
return dict(status='inapplicable', step=step,
missing=tuple(sorted(pre-state)), history=tuple(history))
state = (state-delete) | add
history.append(tuple(sorted(state)))
missing = tuple(sorted(model['goal']-state))
return dict(status='goal-not-met' if missing else 'valid', step=len(names),
missing=missing, history=tuple(history))
DOMAIN = '''(define (domain parcel)
(:requirements :strips)
(:predicates (open) (checked) (sealed))
(:action inspect :parameters () :precondition (open) :effect (checked))
(:action seal :parameters () :precondition (open)
:effect (and (sealed) (not (open)))))'''
PROBLEM = '''(define (problem one-parcel) (:domain parcel)
(:init (open)) (:goal (and (checked) (sealed))))'''
if __name__ == '__main__':
model = load(DOMAIN, PROBLEM)
for plan in [('inspect', 'seal'), ('seal', 'inspect'), ('inspect',), ()]:
print(plan, validate(model, plan))
print('case/comments:', load('; note\n'+DOMAIN.upper(), PROBLEM)==model)
try:
load(DOMAIN.replace(':strips', ':strips :typing'), PROBLEM)
except ValueError as error:
print('unsupported:', error)
The complete example prints:
('inspect', 'seal') {'status': 'valid', 'step': 2, 'missing': (), 'history': (('open',), ('checked', 'open'), ('checked', 'sealed'))}
('seal', 'inspect') {'status': 'inapplicable', 'step': 2, 'missing': ('open',), 'history': (('open',), ('sealed',))}
('inspect',) {'status': 'goal-not-met', 'step': 1, 'missing': ('sealed',), 'history': (('open',), ('checked', 'open'))}
() {'status': 'goal-not-met', 'step': 0, 'missing': ('checked', 'sealed'), 'history': (('open',),)}
case/comments: True
unsupported: only :strips is supported
The first sequence reaches both goal facts. The second fails at step 2 because sealing removed open. Inspection alone is executable but leaves sealed missing. The code does no plan search: rejecting one proposed sequence says nothing about whether another sequence works.
Let count all input characters, the number of declared predicates and the plan length. Under expected hash-table costs, loading takes work and memory. Validation stores a sorted snapshot after each executed action; its loose bounds are:
The plan-character term covers normalization and name checks. The factor k+1 also covers the initial snapshot and final missing-goal sort, even for an empty plan. The bounds exclude the already loaded model and count predicate-name comparisons as unit operations; long names have additional character costs. A streaming validator could use less space by omitting the full history. The syntax reader is iterative, so nesting does not consume Python recursion, but finite available memory still limits document size.
A compatible file can still describe the wrong task
Declaring checked as a goal does not guarantee that the action called inspect represents a meaningful inspection. If its precondition is accidentally empty, the model may admit impossible workflows. If sealing omits its delete effect, the reverse action order may incorrectly pass. These are modelling errors even when the parentheses and names are all valid.
Predicates with arguments let a reusable action schema refer to many objects. Grounding instantiates those parameters, potentially producing many actions; this reader deliberately avoids that separate step. Time, numeric resources and overlapping actions require richer semantics. In particular, a temporal validator’s numerical tolerance is not a feature to copy into this exact Boolean simulation.
The official VAL project provides a broader validation tool. Its fixed-version application guide shows how to check a domain/problem and then a supplied plan. For work beyond this fragment, record the validator version, declared requirements and validation conditions alongside the files. The guide was read for this article; the VAL executable was not run here. VAL application guide at commit 3c7a1f3.
Locate the error before changing the search
Exercise 1: remove sealing’s delete effect
Answer: Replace its effect with (sealed). The sequence seal → inspect now passes because open persists. This reveals a change to the action model, not an improvement in planning. The goal and action names did not change.
Exercise 2: declare typing without implementing it
Answer: Adding :typing makes load reject the domain. Removing the flag while leaving typed declarations does not make them supported; those fields or argument lists are still rejected. Silent fallback would incorrectly claim to have checked the original model.
Exercise 3: omit open from the initial state
Answer: Both actions require open, so either fails as the first action. This complete-state model treats the omitted atom as false. It does not infer that the real parcel is closed, and it does not implement an unknown initial state.
Exercise 4: is every executable plan valid?
Answer: No. ('inspect',) executes but misses sealed, yielding goal-not-met. An empty plan is likewise executable but misses both goals in the original problem. Initializing both checked and sealed would make the empty plan valid under the stated model.
Keep the model and its validation evidence together
- PDDL—The Planning Domain Definition Language, version 1.2, AIPS-98 Planning Competition Committee, October 1998. Original manual. The title and relevant syntax pages were checked visually because the PDF’s extracted text was garbled.
- KCL-Planning, VAL applications. Fixed 2021-10-18 commit. This is documentation evidence, not a report of running VAL or a claim about its current release.
The parcel model, reader, validator and exercises are original. Independent tests compare execution with per-atom Boolean updates, vary comments/case/field order, and distinguish unsupported input from an executable but unsuccessful sequence. Continue with classical planning for search, and temporal logic for properties of branching executions.
Make a prediction, then check
Sealing before inspection returns inapplicable. What does this validation establish?
Learning objectives
- Separate domain, problem, planner and validator; read requirements, preconditions and add/delete effects.
- Run an explicit language-subset reader and distinguish unsupported input, inapplicable actions and unmet goals.
- Explain why plan validity applies to the supplied model and sequence without proving optimality or real-world success.
Prerequisites & connections
Explore related knowledge →References
- PDDL — The Planning Domain Definition Language, version 1.2
AIPS-98 Planning Competition Committee; Drew McDermott (chair) · 1998 - VAL applications — fixed commit 3c7a1f330bdab0ba28a4762bb45c3f06c27fb6d4
KCL-Planning / VAL contributors · 2021
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: primary-source locations, original runnable models, independent finite-state oracles, bilingual review and second-agent cross-checks; not independent human peer review.
- Six author tests passed. Generated actual text for 64 three-atom models, checking all 15 two-action sequences of lengths 0–3: 960 queries against every field of independent per-atom Boolean execution.
- Checked full stdout, case/comments/field order, duplicate initial facts, empty vocabulary/plan, 1,500 nested parentheses and malformed input. Unsupported structures are not skipped; known inapplicable sequences and undeclared action names remain distinct.
- Complete bilingual articles share the program/output, two display equations, six anchors and four answered exercises; actual HTML passed with the repository display-math plugin and strict KaTeX. Costs include the empty-plan initial snapshot, final missing-goal sort and plan strings; English publication spacing corrected.
- Original zero-argument positive STRIPS fragment: no grounding, negative conditions, nested formulas, numeric/time semantics or search. Remains written after AI self-check pending independent review; no full-PDDL or VAL execution claim.
- Read both complete articles, code, six author tests and final metadata; all six tests passed. Loading/API errors, inapplicable, goal-not-met and valid remain distinct. All plan names validate before execution; rejecting one plan is not presented as proving problem unsolvability.
- The independent reference derives each prefix value from that atom’s latest write event, avoiding both production set updates and the author’s rolling bit-state reference. Across 24 four-atom/three-action models using seed 77051, all 961 complete results and histories matched. Independent serialization of known syntax trees checked 96 case, comment, whitespace and field-order variants and every loaded model field. Validation leaves the model unchanged.
- All 39 invalid checks raise ValueError, covering parentheses/top-level shape, repeated or unknown fields, requirements, parameters, nested/negative conditions, conditional and universal effects, opposing effects, problem references, initial forms and plan types/names. Late invalid names are not hidden by earlier semantic failure. A separate missing-delete fixture changes executability rather than search ability.
- A 64-predicate empty-plan fixture checks the initial snapshot and final missing goal. The final bounds include k+1 and L_plan for initial/final sorting and normalized plan strings. Loading is measured against raw character count; validation states expected hashing and unit name comparisons. The contract explicitly trusts a model returned by the loader rather than revalidating edited dictionaries.
- Final strict MDX/KaTeX and actual React HTML pass in both languages: two displays, six anchors and four answered exercises. After decoding HTML entities, MathML TeX annotations exactly match both source equations, including the corrected bounds. Complete code/output agree across languages and direct article targets exist. No whole-site build or browser acceptance was run.
- Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
Source locations checked:
- PDDL — The Planning Domain Definition Language, version 1.2 · Actually downloaded the official university-preserved PDF and viewed local renders of PDF pages 1,3,4,5,6,7. Page1: version1.2, eight committee members, McDermott chair, Yale CVC TR98-003/DCS TR1165, October1998. Page3 printed2: requirements, parameters/preconditions/effects. Page4 printed3: domain reference, initial facts and goal. Pages5–7 printed4–6: EBNF, semicolon comments, domain grammar, flexible field order, separate strict-subset convention, case-insensitive identifiers and default:strips requirements. Web-extracted text was unusable; Washington mirror required login and was not used. Did not inspect remaining pages or infer PDDL2.1 semantics.
- VAL applications — fixed commit 3c7a1f330bdab0ba28a4762bb45c3f06c27fb6d4 · Actually read the live applications guide, then fetched applications/README.md at exact commit3c7a1f330bdab0ba28a4762bb45c3f06c27fb6d4 via GitHub contents API; verified committer date2021-10-18T13:42:14Z. Read Validate section: separate domain/problem and supplied-plan checks, missing preconditions, overall constraints, verbose/tolerance invocation. Temporal epsilon described by VAL was not adopted in the exact sequential Boolean reader. No executable installed or run.
- PDDL — The Planning Domain Definition Language, version 1.2 · Independently viewed the preserved original-manual PNG renders for PDF pages 1, 4, 6 and 7. Page 1 confirms version 1.2, committee, McDermott chair, report numbers and October 1998. Printed page 3 shows the domain reference, initial facts and goal in a problem. Printed page 5 specifies semicolon comments, domain grammar, optional sections, nonempty predicate declarations and field-order freedom. Printed page 6 distinguishes the manual’s separate strict subset, states name/case rules and explains omitted requirements defaulting to :strips. No claim to inspect all 27 pages or validate PDDL 2.1 semantics.
- VAL applications — fixed commit 3c7a1f330bdab0ba28a4762bb45c3f06c27fb6d4 · Independently read the preserved fixed-commit applications README at /tmp/aiwiki-next-pddl/val-readme.md, especially Parser and Validate: separate domain/problem checks, supplied-plan validation, missing preconditions and temporal epsilon. New web fetches of the exact raw URL and commit API failed, so this peer does not claim independent live verification of the commit timestamp. The author records an earlier GitHub API verification of commit 3c7a1f330bdab0ba28a4762bb45c3f06c27fb6d4 and its 2021-10-18 date. No VAL binary was installed, built or run.
Related topics