Skip to content

Instantly share code, notes, and snippets.

@robyfirnandoyusuf
Created August 12, 2025 17:29
Show Gist options
  • Select an option

  • Save robyfirnandoyusuf/13261fd01d7dc435186d341d1a8fdd11 to your computer and use it in GitHub Desktop.

Select an option

Save robyfirnandoyusuf/13261fd01d7dc435186d341d1a8fdd11 to your computer and use it in GitHub Desktop.
simple parser POML
import xml.etree.ElementTree as ET
def load_document(path):
try:
with open(path, 'r', encoding='utf-8') as f:
return f.read()
except FileNotFoundError:
return f"[Document '{path}' not found]"
def render_prompt(poml_path):
tree = ET.parse(poml_path)
root = tree.getroot()
final_prompt = ""
for child in root:
if child.tag == "system":
final_prompt += f"[SYSTEM]: {child.text.strip()}\n"
elif child.tag == "user":
final_prompt += f"[USER]: {child.text.strip()}\n"
elif child.tag == "instructions":
final_prompt += "[INSTRUCTIONS]:\n"
for idx, step in enumerate(child.findall("step"), start=1):
final_prompt += f" {idx}. {step.text.strip()}\n"
elif child.tag == "document":
src = child.attrib.get("src", "")
doc_text = load_document(src)
final_prompt += f"[DOC]: {doc_text.strip()}\n"
return final_prompt.strip()
# Example usage:
if __name__ == "__main__":
prompt = render_prompt("example.poml")
print(prompt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment