Skip to content

prompt as code

Convert code, Python for now, to natural language prompts.

Core trick

Has an LLM write a language-neutral natural-language spec from Python source, then regenerates code from that spec and diffs execution results.

Tags

Description

Convert code, Python for now, to natural language prompts. The prompts can be used later on to generate code with similar functionality in other languages also.
whatdhack/prompt-as-code★ 00 forksPythonCreated May 23, 2026 · last push May 23, 2026

README excerpt

# Prompt-as-Code

A fully automated, AI-driven pipeline that leverages **Meta-Prompt Engineering** to translate Python files into comprehensive, **100% natural-language specifications (prompts)**, executes those prompts to synthesize equivalent clean-room scripts, and validates functional equivalence via automated execution checks and diff analysis.

This repository demonstrates the power of utilizing LLMs (specifically Gemini) to capture pure code behavior in standard English prose—completely decoupled from the original syntactical representation or obfuscated/encoded code segments—and compiling it back into high-quality, fully-functioning Python code.

---

## 📂 Repository Structure

```text
prompt-as-code/
├── example/
│   └── comp_decomp.py             # Original compressor & decompressor python script
├── src/
│   └── main.py                    # Core python orchestrator driving the translation pipeline
├── outputs/
│   ├── comp_decomp.txt            # Synthesized 100% natural language prompt
│   ├── comp_decomp_generated.py   # Synthesized clean-room code generated from running the prompt
│   └── comp_decomp_diff.diff      # Line-by-line unified diff between original and generated
└── README.md                      # This documentation
```

---

## ⚙️ How the Pipeline Works

The execution pipeline inside `src/main.py` works in four stages:

```
┌─────────────────────────┐      1. Meta-Prompting      ┌─────────────────────────┐
│  example/comp_decomp.py │ ───────────────

Team