2 pointsby mikewolfd6 hours ago1 comment
  • mikewolfd6 hours ago
    I built a Python library for saponification chemistry so LLMs can help formulate soap recipes without hallucinating the dangerous parts.

    Ask an LLM to formulate soap and you'll get something that looks reasonable. The oils sound right, the superfat percentage is sensible. But the lye amount? It could be hallucinated. In soap making, a wrong lye calculation isn't a bug, it's caustic soap that burns skin.

    Saponification requires precise NaOH or KOH amounts calculated from SAP values specific to each oil. Get it wrong by a few percentage points and your soap is either caustic or a greasy mess. No room for "close enough."

    This is exactly where LLMs are dangerous alone and useful with the right tooling.

    RECIPES AS CODE

    Web calculators lock your formulas in form fields. soap-calc treats recipes as JSON/YAML you can version in git and pipe through a CLI:

        soap-calc calculate recipe.yaml
        soap-calc validate recipe.yaml
        soap-calc scale recipe.yaml 1500 -o scaled.yaml
    
    A recipe looks like this:

        {
          "name": "Lavender Dream",
          "lye_type": "NaOH",
          "superfat_pct": 5.0,
          "total_oil_weight": 800,
          "oils": [
            { "oil": "Olive Oil", "percentage": 40 },
            { "oil": "Coconut Oil, 76 deg", "percentage": 30 },
            { "oil": "Palm Oil", "percentage": 30 }
          ]
        }
    
    Structured, diffable, and something an LLM can generate while a deterministic program validates the chemistry.

    HOW THIS WORKS WITH LLMS

    Ships with a Claude Code skill and JSON schemas. An LLM can:

    1. Select oils from a verified database (~40 common oils with real SAP values and fatty acid profiles). No hallucinated chemistry.

    2. Generate recipe JSON, then call calculate() for exact lye amounts. Math lives in code, not model weights.

    3. Get validation feedback on property ranges, safety limits, missing fields. Structured errors it can fix.

    Example workflow:

        User: "Make a conditioning bar for dry skin"
          ↓
        LLM: Picks high-oleic oils, writes recipe.json
          ↓
        soap-calc validate + calculate → NaOH: 142.3g, Water: 284.6g
          ↓
        LLM: Returns recipe with verified measurements + property analysis
    
    The LLM handles formulation (which oils for dry skin, how to balance fatty acids). The library handles stoichiometry.

    WHY SOAP MAKING?

    It's a sweet spot for AI-assisted chemistry: well-characterized reactions (base hydrolysis of triglycerides), bounded input space (few dozen common oils), deterministic calculations, but formulation decisions—balancing hardness vs. conditioning, choosing for skin type—genuinely benefit from reasoning.

    WHAT IT DOES

    • Lye calculations (NaOH, KOH, dual-lye)

    • Soap property prediction from fatty acid profiles (hardness, lather, longevity, iodine value, INS)

    • Three water calculation modes

    • Mold-based batch sizing

    • Recipe scaling

    • Markdown export with instructions

    Supports cold process, hot process, and liquid soap.

    Tech: Pure Python, typed models, extensible oil database, MIT licensed. Built with Claude Opus 4.6 and Gemini 3 Pro.

        pip install soap-calc
    
    GitHub: https://github.com/mikewolfd/soap-calc PyPI: https://pypi.org/project/soap-calc/