A direct inference application that transforms legacy mainframe programs (COBOL, etc.) into executable code using Large Language Models. This tool provides instant program analysis, translation, and verification without requiring complex parsing or compilation infrastructure.
- COBOL to Python: Precise translation preserving business logic and mathematical accuracy
- Decimal Precision: Uses Python's
Decimalfor monetary calculations matching COBOL behavior - Control Flow: Exact translation of IF/ELSE, EVALUATE, and conditional logic
- Live Execution: Run generated Python code in isolated environment
- Output Comparison: Verify LLM predictions against actual execution results
- Error Detection: Catch calculation errors and logic bugs automatically
- CLI Inputs: JSON parameter passing via command line
- Interactive Mode: Prompt users for variable values with type detection
- Flexible Defaults: Support for default values and optional parameters
- Token Usage: Track prompt/completion tokens and costs
- Execution Time: Monitor LLM response and code execution performance
- Success Metrics: Validation of prediction accuracy
# 1. Create virtual environment
python -m venv .venv && source .venv/bin/activate
# 2. Install package
pip install -e .
# 3. Configure API key
cp .env.example .env
# Edit .env and set GROQ_API_KEY=your_key_here# Analyze and translate COBOL program
mainframe-llm run --path examples/cobol/premium.cob
# Execute generated Python and compare outputs
mainframe-llm run --path examples/cobol/premium.cob --execute# Prompt user for input values (POL-SUM-INSURED, POL-AGE available)
mainframe-llm run --path examples/cobol/premium.cob --interactive --execute
# Use CLI inputs
mainframe-llm run --path examples/cobol/premium.cob --inputs '{"POL-SUM-INSURED" : 2500, "POL-AGE": 25}' --execute# Dry run (no API call)
mainframe-llm run --path examples/cobol/premium.cob --dry-run
# Use specific model
mainframe-llm run --path examples/cobol/premium.cob --model llama-3.1-70b-versatile> mainframe-llm run --path examples/cobol/premium.cob --inputs '{"POL-SUM-INSURED" : 2500, "POL-AGE": 21}' --execute
Using COBOL-specific prompt
Using CLI input values
Processing premium.cob with model llama-3.1-8b-instant...
**Program Analysis**
Input Variables:
- POL-SUM-INSURED: 2500
- POL-AGE: 21
Working Variables:
- WS-BASE-RATE
- WS-AGE-LOAD
- WS-GROSS
Output Variables:
- POL-SUM-INSURED
- WS-GROSS
**Translated Python Program**
from decimal import Decimal, getcontext
# Set precision for decimal calculations
getcontext().prec = 28
def main():
# Input values from JSON
pol_sum_insured = Decimal('2500.00')
pol_age = 21
# Working variables
ws_base_rate = Decimal('0.0100') # .010 with V9(4) = 0.0100
ws_age_load = Decimal('0.200') # POL-AGE = 21 < 25? TRUE
# Calculate WS-GROSS
ws_gross = pol_sum_insured * ws_base_rate * (1 + ws_age_load)
# Output variables
print("Sum Insured: ", pol_sum_insured)
print("Gross Premium: ", ws_gross)
if __name__ == "__main__":
main()
**Execution and Output**
1. Evaluate all IF/ELSE conditions with actual values:
- POL-AGE = 21
- Condition: 21 < 25? TRUE
- Therefore: IF branch executes
- Result: WS-AGE-LOAD = 0.200 (not 0.100)
2. Calculate intermediate variables in order:
- WS-GROSS = POL-SUM-INSURED * WS-BASE-RATE * (1 + WS-AGE-LOAD)
- WS-GROSS = 2500.00 * 0.0100 * (1 + 0.200)
- WS-GROSS = 2500.00 * 0.0100 * 1.200
- WS-GROSS = 30.00
3. Compute final results using the determined values:
- WS-GROSS = 30.00
Running the Python program produces the following output:
Sum Insured: 2500
Gross Premium: 30.0
**Final Variable Values**
- POL-SUM-INSURED: 2500.00
- WS-GROSS: 30.00
**Step-by-Step Calculation Verification**
1. Input values: POL-SUM-INSURED = 2500, POL-AGE = 21
2. Conditional logic: POL-AGE = 21 < 25? TRUE, so WS-AGE-LOAD = 0.200
3. Final calculation: WS-GROSS = 2500.00 * 0.0100 * (1 + 0.200) = 30.00
VALIDATION CHECKLIST:
โ All monetary values use Decimal type
โ Mathematical operations preserve COBOL precision
โ Control flow matches COBOL logic exactly
โ DISPLAY statements converted to appropriate print() calls
โ Predicted output matches what Python code will actually produce
โ Variable names follow Python conventions (lowercase with underscores)
============================================================
CODE EXECUTION AND COMPARISON
============================================================
โ
Code executed successfully
๐ค Code Execution Output:
Sum Insured: 2500.00
Gross Premium: 30.000000000
๐ฎ LLM Inference Output:
Sum Insured: 2500
Gross Premium: 30.0
๐ Comparison Results:
โ
Numeric values match (formatting differences)
============================================================
============================================================
SYSTEM PERFORMANCE REPORT
============================================================
EXECUTION TIME: 4.484 seconds
PROMPT TOKENS: 1,537
COMPLETION TOKENS: 669
TOTAL TOKENS: 2,206
ESTIMATED COST: $0.028750
VARIABLES PROCESSED: 0
LINES OF CODE: 20
TOKENS/SECOND: 492.0
============================================================- Insurance Premium Calculations: Convert COBOL actuarial programs to Python for modern systems
- Banking Transaction Processing: Translate mainframe batch processing logic
- Risk Assessment Models: Modernize legacy risk calculation algorithms
- Regulatory Compliance: Verify calculations match original COBOL implementations
- Legacy System Migration: Understand business logic before full system rewrites
- Code Documentation: Generate clear explanations of complex legacy algorithms
- Business Rule Extraction: Identify and document embedded business logic
- Prototype Development: Quickly test legacy logic in modern environments
- Algorithm Verification: Validate that modernized code produces identical results
- Regression Testing: Compare outputs between legacy and modern implementations
- Impact Analysis: Test how input changes affect program behavior
- Performance Benchmarking: Compare execution characteristics across platforms
- COBOL Learning: Understand legacy code through Python translations
- Mainframe Concepts: Visualize how mainframe logic works in familiar languages
- Code Review: Analyze legacy programs for optimization opportunities
- Knowledge Transfer: Bridge knowledge gaps between legacy and modern developers
Traditional Approach Challenges:
- Complex parsers and compilers required
- Extensive domain knowledge needed
- Time-intensive development cycles
- Limited flexibility for edge cases
LLM Inference Advantages:
- Instant Results: No compilation or setup required
- Context Awareness: Understands business logic and intent
- Flexible Input: Handles various legacy language dialects
- Self-Documenting: Provides explanations alongside translations
The tool ensures financial-grade accuracy by:
- Using Python's
Decimalfor monetary calculations - Preserving COBOL's implied decimal positioning
- Maintaining exact operator precedence
- Validating results through execution comparison
Unlike static translation tools, this application:
- Executes generated code to verify correctness
- Compares predicted vs actual outputs to catch errors
- Provides immediate feedback on translation quality
- Builds confidence in LLM-generated results
- Financial calculators and pricing prototypes (interest, premiums, fees, accruals) where you can validate results against known formulas.
- Rule engines drafted by the model but executed deterministically (journal templates, eligibility checks, underwriting rules).
- Data mapping/ETL sketches (field mappings, unit conversions, basic validations) before building production pipelines.
- Audit prep and narrative: produce plain-language explanations and test evidence from deterministic outputs.
The application follows a clean, modular design:
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Legacy Code โโโโโถโ LLM Inference โโโโโถโ Python Code โ
โ (COBOL/etc) โ โ (Groq API) โ โ + Predictions โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Comparison โโโโโโ Safe Execution โโโโโโ Input Values โ
โ & Validation โ โ Environment โ โ (Interactive) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
This architecture enables rapid iteration, reliable verification, and seamless integration into existing development workflows.