Build a File-to-Prompt Converter

Turn local files into LLM-ready prompts in 45 minutes

Welcome to another official UVF IT build guide. Today we are constructing a minimal, local-first clone inspired by Mongotar, a tool that converts files into structured prompts for Large Language Models.

This project demonstrates how to use LangChain to parse documents and format them into context-aware prompts, storing the results in a lightweight SQLite database without requiring any paid API keys or cloud infrastructure.

Prerequisites & Simplifications

System Architecture
LOCAL RUNTIME LLM PROVIDER Read Content Generate Prompt Return Structured Prompt Save Result Python App LangChain Logic SQLite Prompt Storage Input Files txt/md/py LLM API OpenAI/Ollama
1

Phase 1: Scaffold Project & Install Dependencies

Create a dedicated directory and virtual environment to isolate dependencies. This ensures your system Python remains clean and your project dependencies are reproducible.

Install LangChain, a document loader, and SQLite support. LangChain provides the abstraction layer for loading documents, while SQLite will serve as our lightweight database for storing the generated prompts.

mkdir mongotar-clone
cd mongotar-clone
python3 -m venv venv
source venv/bin/activate
pip install langchain langchain-community sqlite3
2

Phase 2: Core Feature 1 - File Loading & Text Extraction

Create a Python script that uses LangChain's TextLoader to read a local file. This step isolates the 'file' part of the conversion, ensuring we can extract raw text content reliably before attempting any AI processing.

We will also create a simple test input file to verify that the loader works correctly. By separating file loading from prompt generation, we can debug each component independently.

echo "This is a test document for the Mongotar clone. It contains some sample text to be converted into a prompt." > test_input.txt

loader.py

from langchain_community.document_loaders import TextLoader

def load_document(file_path: str) -> str:
    """
    Loads a text file using LangChain's TextLoader and returns the content.
    """
    try:
        loader = TextLoader(file_path)
        documents = loader.load()
        # Combine all document pages into a single string
        content = "\n".join([doc.page_content for doc in documents])
        return content
    except Exception as e:
        print(f"Error loading file: {e}")
        return None

if __name__ == "__main__":
    file_path = "test_input.txt"
    content = load_document(file_path)
    if content:
        print("--- Loaded Content ---")
        print(content)
        print("-------------------")
    else:
        print("Failed to load content.")
3

Phase 3: Core Feature 2 - Prompt Generation & Storage

In this phase, we bridge the gap between raw text and usable LLM context by creating converter.py. This script imports our loader logic, applies a simple transformation to structure the text into a prompt, and persists the result.

We use SQLite for storage because it requires no server setup and keeps the project entirely local. The code defines a function to format the text and another to handle the database insertion, ensuring each file path is tracked with its generated prompt.

For this minimal clone, we simulate the 'generation' with a deterministic string format. This allows you to verify the data flow without needing an API key immediately. You can easily swap this logic for a real LangChain LLM call later.

converter.py

import sqlite3
import os
from loader import load_text

def generate_simple_prompt(raw_text: str) -> str:
    """
    Simulates LLM prompt generation by wrapping text in a structured format.
    Replace this with a real LLM call (e.g., ChatOpenAI) for production.
    """
    return f"""<system>
You are a helpful assistant. Use the following context to answer questions.
</system>

<user_context>
{raw_text}
</user_context>"""

def init_db(db_path: str = "prompts.db"):
    """Initialize SQLite database and create table if not exists."""
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    cursor.execute("""
        CREATE TABLE IF NOT EXISTS prompts (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            file_path TEXT NOT NULL,
            raw_content TEXT,
            generated_prompt TEXT,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        )
    """)
    conn.commit()
    return conn

def save_prompt(conn, file_path: str, raw_content: str, prompt: str):
    """Save the generated prompt to the database."""
    cursor = conn.cursor()
    cursor.execute("""
        INSERT INTO prompts (file_path, raw_content, generated_prompt)
        VALUES (?, ?, ?)
    """, (file_path, raw_content, prompt))
    conn.commit()
    print(f"Saved prompt for: {file_path}")

def main():
    # 1. Load the test file
    file_path = "test_input.txt"
    if not os.path.exists(file_path):
        print(f"Error: {file_path} not found. Please create it first.")
        return
    
    raw_text = load_text(file_path)
    
    # 2. Generate the prompt
    prompt = generate_simple_prompt(raw_text)
    
    # 3. Save to SQLite
    conn = init_db()
    save_prompt(conn, file_path, raw_text, prompt)
    conn.close()

if __name__ == "__main__":
    main()
4

Phase 4: Run Locally & Verify

Now that the code is ready, we execute the pipeline. First, ensure your test_input.txt exists with some sample content, then run the converter script.

The script will read the file, generate the structured prompt, and save it to prompts.db. You should see a confirmation message in the terminal.

Finally, we verify the data integrity by querying the SQLite database directly. This confirms that the end-to-end flow from file to database is working as expected.

# Create a simple test file if it doesn't exist
if [ ! -f test_input.txt ]; then
    echo "This is a test document for the Mongotar clone." > test_input.txt
    echo "It contains some sample text to be converted into a prompt." >> test_input.txt
fi

# Run the converter
python converter.py

# Verify the database contents
sqlite3 prompts.db "SELECT id, file_path, substr(generated_prompt, 1, 50) as prompt_preview FROM prompts;"

Verifying the Stack

CheckCommand / Why it matters
Virtual environment is active and dependencies are installed.pip list | grep langchain
Test input file is created and readable.cat test_input.txt
Converter script runs without errors.python converter.py
SQLite database contains the generated prompt.sqlite3 prompts.db "SELECT count(*) FROM prompts;"

Next Steps

To extend this clone, integrate a real LLM provider like Ollama or OpenAI by replacing the generate_simple_prompt function with a LangChain ChatModel call. You can also add a simple Streamlit UI to browse and copy prompts directly from the browser.