Templates

It is highly recommended to use the base templates to properly extract LLM output into the designated Python formats from these methods.

Below are some examples of the base prompt structure that should be used in this library with your customized prompt using the PromptBuilder class. More details of each methods’ prompt structure is found in l2p/templates.

There are four main folders found in /templates:

templates/domain
  • /prompt_types.md: for ``DomainBuilder.formalize_component(model, PDDLType, ...)``
  • /prompt_constants.md: for ``DomainBuilder.formalize_component(model, Constant, ...)``
  • /prompt_predicates.md: for ``DomainBuilder.formalize_component(model, Predicate, ...)``
  • /prompt_functions.md: for ``DomainBuilder.formalize_component(model, Function, ...)``
  • /prompt_derived_predicates.md: for ``DomainBuilder.formalize_component(model, DerivedPredicate, ...)``
  • /prompt_requirements.md: for ``DomainBuilder.formalize_component(model, Requirement, ...)``
  • /prompt_parameters.md: for ``DomainBuilder.formalize_component(model, Parameter, ...)``
  • /prompt_preconditions.md: for ``DomainBuilder.formalize_component(model, ActionPrecondition, ...)``
  • /prompt_effects.md: for ``DomainBuilder.formalize_component(model, ActionEffect, ...)``
  • /prompt_actions.md: for ``DomainBuilder.formalize_component(model, Action, ...)``
  • /prompt_nl_actions.md: for ``DomainBuilder.extract_nl(model, "nl_actions", ...)``
  • /prompt_durative_actions.md: for ``DomainBuilder.formalize_component(model, DurativeAction, ...)``
  • /prompt_durative_conditions.md: for ``DomainBuilder.formalize_component(model, DurativeActionConditions, ...)``
  • /prompt_durative_effects.md: for ``DomainBuilder.formalize_component(model, DurativeActionEffect, ...)``
  • /prompt_nl_durative_actions.md: for ``DomainBuilder.extract_nl(model, "nl_durative_actions", ...)``
  • /prompt_events.md: for ``DomainBuilder.formalize_component(model, Event, ...)``
  • /prompt_processes.md: for ``DomainBuilder.formalize_component(model, Process, ...)``
  • /prompt_constraints.md: for ``DomainBuilder.formalize_component(model, Constraint, ...)``
templates/problem
  • /prompt_problem.md: for ``ProblemBuilder.formalize_component(model, ProblemDetails, ...)``
  • /prompt_objects.md: for ``ProblemBuilder.formalize_component(model, PDDLObject, ...)``
  • /prompt_initial_states.md: for ``ProblemBuilder.formalize_component(model, InitialState, ...)``
  • /prompt_goal_states.md: for ``ProblemBuilder.formalize_component(model, GoalState, ...)``
  • /prompt_metric.md: for ``ProblemBuilder.formalize_component(model, Metric, ...)``
  • /prompt_constraints.md: for ``ProblemBuilder.formalize_component(model, Constraint, ...)``
templates/feedback
  • /prompt_diagnosis.md: for ``FeedbackBuilder.llm_diagnose()``
  • /prompt_evaluate.md: for ``FeedbackBuilder.llm_evaluate()``
  • /prompt_reflection.md: for ``FeedbackBuilder.llm_reflect()``
  • /prompt_revise.md: for ``FeedbackBuilder.llm_revise()``
  • /prompt_select.md: for ``FeedbackBuilder.llm_select()``
  • /prompt_plan_evaluate.md: for ``FeedbackBuilder.llm_evaluate_plan()``
  • /prompt_plan_diagnosis.md: for ``FeedbackBuilder.llm_diagnose_plan()``
templates/custom (Multi-Component)

These templates extract multiple PDDL components in a single LLM call, improving cross-component consistency. Use them with formalize_component(model, cls_list=[...], ...).

  • /prompt_types_predicates.md: Types + Predicates
  • /prompt_types_constants_predicates.md: Types + Constants + Predicates
  • /prompt_types_predicates_functions.md: Types + Predicates + Functions
  • /prompt_types_predicates_functions_actions.md: Types + Preds + Functions + Actions
  • /prompt_predicates_actions.md: Predicates + Actions
  • /prompt_actions_constraints.md: Actions + Constraints
  • /prompt_actions_durative_actions.md: Actions + DurativeActions
  • /prompt_events_processes.md: Events + Processes
  • /prompt_derived_predicates_predicates.md: DerivedPredicates + Predicates
  • /prompt_objects_initial_state.md: Objects + InitialState
  • /prompt_objects_initial_goal.md: Objects + Init + Goal
  • /prompt_initial_goal_metric.md: Init + Goal + Metric

Domain Extraction Prompts Example

This is an example using the PromptBuilder class:

 1from l2p import Action
 2from l2p import PromptBuilder
 3
 4role_desc = "You are a PDDL action constructor. Your job is to take " \
 5"the task given in natural language and convert it into PDDL actions."
 6
 7format_desc = "You must follow the strict JSON object defined below. " \
 8"Enclose your final answer in <actions> ... </actions> tags."
 9
10pb = (PromptBuilder()
11    .set_role(role_str=role_desc)
12    .set_format(format_str=format_desc)
13    .set_format_example(component=Action) # set extraction example block for component
14    .add_rule(rule_str="Every action parameter must reference a defined type.")
15    .add_rule(rule_str="Preconditions and effects must only use defined predicates.")
16    .add_example("INPUT: ...\nOUTPUT: ...")
17    .add_example("INPUT: ...\nOUTPUT: ...")
18    .set_task("Generate actions for a logistics domain."))
19
20print(pb.generate_prompt())
21# alternatively - pb.save_prompt(filename="my_prompt.md")

The following is the output:

## ROLE
You are a PDDL action constructor. Your job is to take the task given in natural language and convert it into PDDL actions.

## OUTPUT FORMAT
You must follow the strict JSON object defined below. Enclose your final answer in <actions> ... </actions> tags.

<actions>
[
    {
        "name": "move-rover",
        "params": [
            {
                "variable": "?r",
                "type": "rover"
            },
            {
                "variable": "?from",
                "type": "waypoint"
            },
            {
                "variable": "?to",
                "type": "waypoint"
            }
        ],
        "preconditions": {
            "conditions": [
                "(at ?r ?from)",
                {
                    "operator": "not",
                    "condition": "(= ?from ?to)"
                }
            ],
            "desc": "Optional (str)"
        },
        "effects": {
            "add": [
                "(at ?r ?to)"
            ],
            "delete": [
                "(at ?r ?from)"
            ],
            "numeric": [
                "(decrease (battery-level ?r) 10.0)"
            ],
            "conditional": [
                {
                    "condition": [
                        "(has-rock-sample ?r)"
                    ],
                    "effect": {
                        "add": [
                            "(carrying-heavy-load ?r)"
                        ],
                        "delete": [],
                        "numeric": []
                    }
                }
            ],
            "desc": "Optional (str)"
        },
        "desc": "Optional (str)"
    }
]
</actions>

## RULES
1. Every action parameter must reference a defined type.
2. Preconditions and effects must only use defined predicates.

## EXAMPLE(S)
# Example 1:
INPUT: ...
OUTPUT: ...

# Example 2:
INPUT: ...
OUTPUT: ...
--------------------------------------------------

## TASK
Generate actions for a logistics domain.

{description}

{context}

Users have the flexibility to customize all aspects of their prompts, with the exception of the provided base template. While users can include few-shot examples to guide the LLM, the base template must remain intact during inference.