Skip to content
vortezwohlPublic

About

Programmatic prompt template for Python.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

39 Commits

Folders and files

Repository files navigation

Prompt4Py

Programmatic prompt template for Python.

Prompt Engineering Skill

Prompt4Py includes the prompt-engineering agent skill for designing, reviewing, and validating prompts as controlled reasoning interfaces.

For a non-trivial prompt task, the skill helps an agent:

  • define one objective, clear evidence boundaries, and a machine-checkable output contract;
  • separate instructions, constraints, reusable context, and runtime input;
  • keep retries, persistence, acceptance, and other workflow responsibilities in code or an external harness;
  • validate the prompt structure before delivery and report remaining unknowns honestly.

The goal is not more prompt text. It is a smaller, explicit decision surface with a verification path. Prompt4Py is the recommended Python implementation when a structured template is needed.

Why Prompt4Py?

Prompt4Py is inspired by two practical ideas:

  • Prompts should be structured, programmable artifacts: define templates in Python and render them with runtime values.
  • Prompt layout is part of the design. The placement of instructions, context, and few-shot examples can affect LLM performance, so templates keep these elements explicit and controllable.

Research on Demos' Position in Prompt (DPP) bias shows that moving demonstrations within a prompt can materially affect accuracy and output stability. See Cobbina and Zhou, Where to show Demos in Your Prompt: A Positional Bias of In-Context Learning (2025).

Installation

Python SDK

pip install -U prompt4py

Prompt Engineering Skill

Codex

$skill-installer install https://github.com/vortezwohl/Prompt4Py/tree/main/.skills/prompt-engineering

Restart Codex after installation.

Other Agent Skills-compatible tools

Copy .skills/prompt-engineering/ into the tool's supported skills location, then invoke:

prompt-engineering

Important

Review SKILL.md, its references, and its validation script before installing it. A skill is executable agent guidance.

Quick Start

  1. Create a prompt template

    from prompt4py import GeneralTemplate
    
    # Create your prompt template
    prompt_template = GeneralTemplate()
    prompt_template.role = 'An NER machine'
    prompt_template.objective = 'Extract all {{entity_type}} from CONTEXT.'
    prompt_template.instruction = {
        1: 'Think deeply on every entities in CONTEXT',
        2: 'Extract all {{entity_type}}',
        3: 'Output the entities you have extracted'
    }
    prompt_template.constraint = 'Do not include any markdown grams'
    prompt_template.capability = 'Extract entities'
    prompt_template.context = '{{ent_1}}, {{ent_2}}, {{ent_3}}'
    prompt_template.output_dtype = 'str'
    prompt_template.output_format = 'jsonl'
    prompt_template.output_example = str([
        {
            'entity_type': '{{example_entity_type_1}}',
            'entity_text': '{{example_entity_text_1}}'
        }
    ])
  2. Render the template

    # Render the template
    prompt = prompt_template.render(entity_type='PERSON', ent_1='John Lennon', ent_2='Joe Biden', ent_3='Charlemagne',
                                    example_entity_type_1='PERSON', example_entity_text_1='Elizabeth')
    print(prompt)

    the prompt would be rendered like this:

    ## _TIMESTAMP
    [82159.8475038]
    ## ROLE
    An NER machine
    ## OBJECTIVE
    Extract all PERSON from CONTEXT.
    ## INSTRUCTION
    - **1**: Think deeply on every entities in CONTEXT 
    - **2**: Extract all PERSON 
    - **3**: Output the entities you have extracted 
    ## CONSTRAINT
    Do not include any markdown grams
    ## CAPABILITY
    Extract entities
    ## CONTEXT
    John Lennon, Joe Biden, Charlemagne
    ## OUTPUT_DATATYPE
    str
    ## OUTPUT_FORMAT
    jsonl
    ## OUTPUT_EXAMPLE
    [{'entity_type': 'PERSON', 'entity_text': 'Elizabeth'}]
  3. Invoke a chatbot / causal language model

    You would get response like below:

    {"entity_type": "PERSON", "entity_text": "John Lennon"}
    {"entity_type": "PERSON", "entity_text": "Joe Biden"}
    {"entity_type": "PERSON", "entity_text": "Charlemagne"}
    

About

Programmatic prompt template for Python.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages