TRANSMISSION // 2604.12311v3

When AI-written safety code runs—but gets the answer wrong

Source published

A study of 450 AI-generated construction-safety scripts found that many ran successfully while still failing OSHA logic. The results highlight why working code is not necessarily safe code.

AI-generated conceptual illustration for When AI-written safety code runs—but gets the answer wrong
AI-generated conceptual illustration; not documentary evidence.

Could a script that runs without errors still give construction workers unsafe advice? In a study of AI-generated safety calculators, nearly half of the scripts that ran successfully were judged to contain incorrect OSHA logic. The finding is a warning about treating functional code as verified engineering.

The question: does working code mean safe code?

“Vibe coding” means asking an AI system to create software from ordinary-language instructions, with little or no line-by-line coding by the user. It can make small tools easier to produce, but construction-safety calculations are not a low-stakes place to rely on code that merely appears to work. A calculator can run without crashing and still apply the wrong formula or assume information the user never provided.

S M Jamil Uddin’s study examined how often that gap appeared in AI-generated Python tools for construction safety. The supplied paper text says the work has been published in the Journal of Information Technology in Construction and gives a publication DOI. The supplied arXiv record identifies the paper, but the available material does not establish how its arXiv version relates to the published version. This article therefore describes the study based on the supplied paper text.

How the test was set up

The study used 150 prompts describing requests for safety tools, divided among three simulated user personas: a regulation-focused safety manager, a time-pressured construction foreman, and a frontline worker whose prompts were more informal and incomplete. The prompts covered tasks such as fall protection, scaffolding, trenches, and crane loads. Each of three AI models—Claude 3.5 Haiku, GPT-4o-Mini, and Gemini 2.5 Flash—received the same prompts, producing 450 scripts in total.

The researchers asked each model to produce non-interactive Python code and instructed it to hardcode test values when information was missing. They ran the scripts in an isolated sandbox, with a five-second limit and standard input disabled. A separate AI judge assessed whether the scripts invented missing values, included basic error handling, followed OSHA requirements, and gave a clear safety directive rather than just a number. Two software developers also reviewed a random subset of 90 scripts using the same rubric.

That distinction matters: the human review checked agreement in applying the rubric, not whether construction-safety experts independently certified every calculation.

What the scripts did

Of the 450 scripts, 384—about 85%—ran successfully. But successful execution was not a reliable sign that the underlying safety logic was correct. Among those 384 working scripts, 174 were classified as silent failures: code that ran but failed the study’s OSHA-logic assessment. That is 45.3%, with a reported 95% confidence interval of 40.3% to 50.4%.

The share classified as silent failures varied by model: 56.3% of GPT-4o-Mini’s executable scripts, 41.4% of Gemini 2.5 Flash’s, and 35.3% of Claude 3.5 Haiku’s. These figures apply to the scripts that ran, not to all generated scripts. Claude’s lower rate also came alongside a lower execution rate, so it should not be read as a simple overall ranking of safety.

The study also found that scripts based on the less formal, less specific personas more often used invented site-specific values. The reported rates were 64.7% for the safety-manager prompts, 82.0% for foreman prompts, and 87.3% for worker prompts. However, the models had explicitly been told to hardcode values when information was missing. The rates therefore show how often the scripts relied on invented values under that instruction—not an unprompted tendency to make assumptions. Because the personas differed in several ways at once, the experiment also cannot isolate the effect of informal wording from missing detail or regulatory specificity.

Basic defensive programming was uncommon: the paper reports error handling in 16% of scripts overall. And 31.6% of all scripts did not provide a clear, actionable safety directive, such as a plain-language warning.

What the results do—and don’t—show

The central lesson is narrow but important: code that executes is not necessarily code that correctly implements a safety rule. The study did not test these tools on construction sites or measure injuries, nor did it test whether safeguards could reduce error rates. Its suggested approach—using AI to interpret requests while sending calculations to pre-validated, deterministic software—is a proposed design, not an intervention evaluated in the experiment.

The results are limited to three model versions, synthetic prompts, Python scripts, and the OSHA standards considered by the authors. The prompts were not balanced across hazard topics. The AI judge was not supplied with regulatory text and could itself have incomplete or outdated knowledge; its classifications may therefore be wrong. The human reviewers were software developers, not OSHA specialists. These qualifications make the reported rates evidence about this particular test, not a universal estimate for every model, prompt, or real-world deployment.

For curious users, the practical takeaway is not that AI cannot help with safety work. It is that a working calculator is not proof of a safe one. In high-stakes settings, generated code needs independent domain review and validated calculations before anyone relies on its output.

Automatically matched by shared topic keywords. These links do not imply that the sources agree or establish a consensus.