# AI engineering calculations you can check and repeat

> Chatbots don't give the same right answer twice. Pantha writes engineering calcs as .qmd reports where Python computes every number.

AI (artificial intelligence) gets engineering calculations right some of the time, and you can't tell which time.

The fix is to have the AI write the calculation report in the `.qmd` format.

This results in not only increased confidence in results (as calculations are produced deterministically from embedded Python scripts) but also repeatability - you set up the calculation report once, and the AI can easily update the calculation inputs relevant to the specifics of the problem.

## Why AI engineering calculations go wrong

With reasoning turned on, leading models are now [good at raw arithmetic](https://sanand0.github.io/llmevals/2026-10-llm-math/). The problem is that they are probabilistic: they predict the most likely answer rather than calculate it. In practice that shows up three ways:

- **Same question, different answer**: even at temperature 0, AI models [don't return the same output every time](https://thinkingmachines.ai/blog/defeating-nondeterminism-in-llm-inference/).

- **More complexity, less accuracy**: Apple found that reasoning models' [accuracy collapses beyond a certain problem complexity](https://machinelearning.apple.com/research/illusion-of-thinking).

- **Wrong answers presented as right**: OpenAI says models [hallucinate because training rewards confident guessing](https://openai.com/index/why-language-models-hallucinate/) over admitting uncertainty.

The fix is to give the AI the right context (method, clause and inputs) and to let deterministic code, not the model, produce the numbers. This allows the LLM (large language model) to have a significantly higher chance to predict the correct answer in a more repeatable way.

## Options

Some options we can consider to resolve the context and determinism issues are as follows:

- **Chatbot with the standard and method attached** (e.g. a ChatGPT Project or Custom GPT)
  - Context: better. The AI can read the clause and your preferred method.
  - Determinism: no. The model still predicts the numbers, so the answer can change between chats.
- **Chatbot with a code interpreter**
  - Context: only what you paste into that chat.
  - Determinism: partial. Python computes the numbers, but the code is rewritten fresh each chat, so the method can change.
- **Spreadsheet template**
  - Context: the method is fixed in the cell formulas, but the clause and assumptions are hidden in cells.
  - Determinism: yes. Same inputs, same answer. But the working is hard to review.
- **`.qmd` calculation report**
  - Context: the workflow, process, method, clause references and inputs live in the report.
  - Determinism: yes. Python computes every number, and the saved code re-runs the same way on the next job.

## Recommendation: a .qmd calculation report

A `.qmd` file is a [Quarto](https://quarto.org) document: prose and equations, with the calculation as Python code in between. When Quarto renders it, the code runs and the results are written into the report, for example a PDF or DOCX (Microsoft Word document) file.

That solves each problem above:

- **Same question, different answer**: the numbers come from saved Python code, not the model, so the same inputs always give the same result.
- **More complexity, less accuracy**: the method, clauses and inputs are written into the report, so the AI follows a fixed method instead of working it out from scratch each time.
- **Wrong answers presented as right**: every input, formula and clause is in the document, so mistakes are visible and can be checked.

Each fix comes down to the same two things: the report gives the AI accurate context to work from, and Python, not the model, produces the numbers. Resulting in a much higher likelihood of the correct output being produced.

A domain expert builds the report once with the AI: they choose the method, check the code against the standard and approve it. On the next job, you change the inputs and re-run it. If the code is right, every number is right, and it stays right when the inputs change.

## Worked example: ASME B31.3 minimum wall thickness

An NPS (Nominal Pipe Size) 6 carbon steel process line is due for its integrity review. The latest UT (ultrasonic testing) survey found a minimum wall of 5.8 mm. Is it still fit for its 8 MPa (megapascal) design pressure?

[ASME (American Society of Mechanical Engineers) B31.3](https://www.asme.org/codes-standards/find-codes-standards/b31-3-process-piping) para. 304.1.2 gives the pressure design thickness of straight pipe, valid for $$t < D/6$$:

$$
t = \frac{PD}{2(SEW + PY)}, \qquad t_m = t + c
$$

Where $$P$$ is the design pressure, $$D$$ the outside diameter, $$S$$ the allowable stress (Table A-1M), $$E$$ the quality factor (Table A-1B), $$W$$ the weld joint strength reduction factor (para. 302.3.5), $$Y$$ the coefficient from Table 304.1.1 and $$c$$ the corrosion allowance. The line passes if the measured wall is at least $$t_m$$.

### The .qmd file

An AI writes the whole report as one file: every input with its source, the method with its clause references, and the Python that computes every number. To run it yourself, save it as `calc.qmd`, install [Quarto](https://quarto.org/docs/get-started/) and `pip install handcalcs`, then run `quarto render calc.qmd`.

````markdown
---
title: "ASME B31.3 minimum wall thickness"
subtitle: "NPS 6 carbon steel process line, UT survey 2026"
execute:
  echo: false
  output: asis
---

```{python}
#| include: false
from handcalcs.decorator import handcalc

# Every input with its unit and source, so the reviewer can check it without asking.
inputs = {
    "P": (8.0, "MPa", "Line list, design pressure"),
    "T": (150, "°C", "Line list, design temperature"),
    "D": (168.3, "mm", "NPS 6 outside diameter, ASME B36.10M"),
    "S": (138.0, "MPa", "B31.3 Table A-1M, A106 Gr B at 150 °C"),
    "E": (1.0, "", "B31.3 Table A-1B, seamless"),
    "W": (1.0, "", "B31.3 para. 302.3.5, below 427 °C"),
    "Y": (0.4, "", "B31.3 Table 304.1.1, ferritic below 482 °C"),
    "c": (1.5, "mm", "Piping class corrosion allowance"),
    "t_meas": (5.8, "mm", "UT survey 2026, minimum reading"),
}
globals().update({name: value for name, (value, unit, source) in inputs.items()})
```

## Inputs

```{python}
print("")
print("| Input | Value | Unit | Source |")
print("|:---|---:|:---|:---|")
for name, (value, unit, source) in inputs.items():
    print(f"| `{name}` | {value} | {unit} | {source} |")
print("")
```

## Pressure design thickness (B31.3 para. 304.1.2)

Valid for straight pipe where $t < D/6$.

```{python}
@handcalc(override="long", jupyter_display=False, precision=2)
def _thickness(P=P, D=D, S=S, E=E, W=W, Y=Y, c=c):
    t = P * D / (2 * (S * E * W + P * Y))  # pressure design thickness, mm
    t_m = t + c  # minimum required thickness, mm
    return locals()

_latex, _vars = _thickness()
print(_latex)
globals().update(_vars)
assert t < D / 6, "para. 304.1.2 only applies where t < D/6"
```

## Result

```{python}
checks = [
    ("Pressure design thickness, $t$", "304.1.2", f"{t:.2f} mm", f"{t_meas:.2f} mm", t / t_meas),
    ("Minimum required thickness, $t_m = t + c$", "304.1.2", f"{t_m:.2f} mm", f"{t_meas:.2f} mm", t_m / t_meas),
]

print("")
print("| Check | Clause | Required | Actual | Utilisation | Result |")
print("|:---|:---|---:|---:|---:|:---|")
for check, clause, required, actual, utilisation in checks:
    result = "PASS" if utilisation <= 1 else "**FAIL**"
    print(f"| {check} | {clause} | {required} | {actual} | {utilisation:.2f} | {result} |")
print("")
```
````

### What it renders to

A preview of the report Quarto produces. The Python is hidden, and handcalcs prints each formula with the inputs substituted, so a reviewer can check the working line by line.

<ReportPreview>

# ASME B31.3 minimum wall thickness

NPS 6 carbon steel process line, UT survey 2026

## Inputs

| Input    | Value | Unit | Source                                     |
| :------- | ----: | :--- | :----------------------------------------- |
| `P`      |   8.0 | MPa  | Line list, design pressure                 |
| `T`      |   150 | °C   | Line list, design temperature              |
| `D`      | 168.3 | mm   | NPS 6 outside diameter, ASME B36.10M       |
| `S`      | 138.0 | MPa  | B31.3 Table A-1M, A106 Gr B at 150 °C      |
| `E`      |   1.0 |      | B31.3 Table A-1B, seamless                 |
| `W`      |   1.0 |      | B31.3 para. 302.3.5, below 427 °C          |
| `Y`      |   0.4 |      | B31.3 Table 304.1.1, ferritic below 482 °C |
| `c`      |   1.5 | mm   | Piping class corrosion allowance           |
| `t_meas` |   5.8 | mm   | UT survey 2026, minimum reading            |

## Pressure design thickness (B31.3 para. 304.1.2)

Valid for straight pipe where $$t < D/6$$.

$$
\begin{aligned}
t &= \frac{ P \cdot D }{ 2 \cdot \left( S \cdot E \cdot W + P \cdot Y \right) } \\
&= \frac{ 8.0 \cdot 168.3 }{ 2 \cdot \left( 138.0 \cdot 1.0 \cdot 1.0 + 8.0 \cdot 0.4 \right) } \\
&= 4.77 \; \textrm{(pressure design thickness, mm)} \\[10pt]
t_{m} &= t + c \\
&= 4.77 + 1.5 \\
&= 6.27 \; \textrm{(minimum required thickness, mm)}
\end{aligned}
$$

## Result

| Check                                       | Clause  | Required |  Actual | Utilisation | Result   |
| :------------------------------------------ | :------ | -------: | ------: | ----------: | :------- |
| Pressure design thickness, $$t$$            | 304.1.2 |  4.77 mm | 5.80 mm |        0.82 | PASS     |
| Minimum required thickness, $$t_m = t + c$$ | 304.1.2 |  6.27 mm | 5.80 mm |        1.08 | **FAIL** |

</ReportPreview>

### Result

The line still holds its design pressure today: 5.8 mm is above the 4.77 mm pressure design thickness $$t$$. But it no longer carries the 1.5 mm corrosion allowance, so it is below the B31.3 minimum required thickness $$t_m$$ of 6.27 mm and needs action.

<Callout type="warning" title="Remediation options">
  - **Derate**: lower the design pressure until $$t_m$$ is no more than the measured wall (re-run the report with a lower $$P$$).
  - **Replace** the corroded spool with new Sch (Schedule) 40 pipe.
  - **Assess fitness for service** to API (American Petroleum Institute) 579-1/ASME FFS-1 (Fitness-For-Service) if the thinning is local, and shorten the inspection interval under [API 570](https://www.api.org/products-and-services/standards).

The report is a design aid. The responsible engineer reviews it, picks the remediation and signs it off.

</Callout>

Change `t_meas` to 5.6 mm and the report re-renders in seconds with the same checks: the required thickness stays 6.27 mm, the utilisation rises, and the result is still FAIL.

## Try it on your next calc

Pantha can run this on your own computer, works with the files where they already live, and shows every step it takes. Download the [QMD calculation reports skill](/products/pantha/skills/qmd-calculation-reports) and run your first check today.

<DownloadCta />

## FAQ

<Faqs>
  <Faq question="ChatGPT can already run Python. What's different?">
    The code is saved in your project folder next to its inputs, it reliably
    re-runs the same way every time. It doesn't disappear into a chat, and your
    files don't get uploaded to run it.
  </Faq>
  <Faq question="Can the AI still get the calculation wrong?">
    Yes, in the code it writes, for example a wrong clause or a units slip. The
    difference is that the mistake is visible in a short file you can review,
    and once it's fixed it stays fixed for every future run.
  </Faq>
  <Faq question="Is the report certified?">
    No. It's a design aid. The responsible engineer reviews and signs it, just
    like a junior's calc.
  </Faq>
  <Faq question="Which standards does it support?">
    Any standard you name, including ASME, API and AS (Australian Standards)
    codes. Pantha cites the clause for each formula so you can check it against
    your copy of the standard.
  </Faq>
</Faqs>
