Use case

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.

JA
Josh Adams

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. The problem is that they are probabilistic: they predict the most likely answer rather than calculate it. In practice that shows up three ways:

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 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 para. 304.1.2 gives the pressure design thickness of straight pipe, valid for t<D/6t < D/6:

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

Where PP is the design pressure, DD the outside diameter, SS the allowable stress (Table A-1M), EE the quality factor (Table A-1B), WW the weld joint strength reduction factor (para. 302.3.5), YY the coefficient from Table 304.1.1 and cc the corrosion allowance. The line passes if the measured wall is at least tmt_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 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:
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.

ASME B31.3 minimum wall thickness

NPS 6 carbon steel process line, UT survey 2026

Inputs

InputValueUnitSource
P8.0MPaLine list, design pressure
T150°CLine list, design temperature
D168.3mmNPS 6 outside diameter, ASME B36.10M
S138.0MPaB31.3 Table A-1M, A106 Gr B at 150 °C
E1.0B31.3 Table A-1B, seamless
W1.0B31.3 para. 302.3.5, below 427 °C
Y0.4B31.3 Table 304.1.1, ferritic below 482 °C
c1.5mmPiping class corrosion allowance
t_meas5.8mmUT survey 2026, minimum reading

Pressure design thickness (B31.3 para. 304.1.2)

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

t=P⋅D2⋅(S⋅E⋅W+P⋅Y)=8.0⋅168.32⋅(138.0⋅1.0⋅1.0+8.0⋅0.4)=4.77  (pressure design thickness, mm)tm=t+c=4.77+1.5=6.27  (minimum required thickness, mm)\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

CheckClauseRequiredActualUtilisationResult
Pressure design thickness, tt304.1.24.77 mm5.80 mm0.82PASS
Minimum required thickness, tm=t+ct_m = t + c304.1.26.27 mm5.80 mm1.08FAIL

Result

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

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. Contact us for the calc-report skill file and run your first check today.

Try it forFreeEvery new account gets 1M credits.

FAQ

More to read