AI-Generated Code in Safety-Critical Devices: Can It Be Trusted?
AI-generated code can be used in safety-critical devices, but it should not be trusted simply because it compiles, passes a few tests, or was produced by a capable model. It needs the same disciplined requirements, review, verification, and lifecycle controls as other software—and teams must account for errors that AI tools can introduce or make harder to spot.
What makes software safety-critical?
Software is safety-critical when its failure could contribute to death, injury, major equipment damage, or serious environmental harm. Examples include code that controls braking or flight functions, administers a medical device’s operation, manages industrial machinery, or monitors a power system. The software may be only one part of a larger safety system, but its behavior can still affect risk.
That does not mean every line in such a product has the same safety role. A display, logging feature, or maintenance utility may be separated from a control function. Safety analysis identifies hazards, defines the software’s responsibilities, and determines what controls are needed. The level of assurance depends on the device, its intended use, applicable standards, and the consequences of failure.
AI-generated code can mean several things: code suggested by an autocomplete tool, a function drafted from a prompt, or a larger component produced by an AI system. Human-written code may also be revised with AI assistance. In all cases, the important question is not who typed the code, but whether the final system has adequate evidence that it meets its requirements and behaves safely.
How AI-generated code changes the development process
Generative tools predict likely code from their training and the context they receive. They can produce useful starting points quickly, but they do not inherently understand a device’s complete requirements, hazard analysis, hardware behavior, or operating environment. A plausible-looking answer can contain a subtle logic error, misuse an interface, omit an edge case, or rely on an assumption that is false for the target system.
AI assistance can also affect what developers review. A large suggested change may be accepted without close inspection, and generated code can look conventional even when it is wrong. Conversely, AI may help draft repetitive code, tests, documentation, or review checklists, freeing people to focus on higher-risk decisions. These are potential workflow benefits, not proof of safety.
Generated code should be treated as a proposal. The team remains responsible for understanding it, checking its origin and dependencies, and controlling how it enters the product. If a tool’s behavior, version, settings, or output cannot be traced well enough for the project’s assurance needs, that is a governance issue to resolve—not a reason to assume the code is reliable.
What evidence supports trust?
Trust comes from a chain of evidence: clear requirements, a controlled design, implementation that can be reviewed, and verification that addresses both normal operation and failure conditions. AI-generated code does not remove any of these needs. Depending on the device and applicable process, useful controls may include:
- Traceability: Link each relevant requirement to the code and to tests or analyses that verify it.
- Human review: Have qualified reviewers check logic, interfaces, assumptions, error handling, and consistency with the architecture.
- Testing: Use unit, integration, system, boundary, and fault-related tests as appropriate. Test results are stronger when test cases come from requirements rather than from the same generated implementation.
- Static analysis and builds: Check for defects and enforce reproducible, controlled build and configuration practices where required.
- Independent verification: For higher-risk functions, use review or test methods that reduce the chance of the same mistaken assumption appearing in both code and its check.
- Change control: Record tool use where it matters, review modifications, preserve configuration and test evidence, and assess the impact of updates.
These activities are not interchangeable. Passing tests cannot establish that the requirements are complete, and code review alone cannot demonstrate every runtime property. The assurance argument should fit the hazards and the relevant standards or regulatory framework; requirements vary by industry and jurisdiction.
Common risks and misconceptions
A common misconception is that AI-generated code is unsafe by definition. That is too broad: a tool can assist with code that is then carefully verified. The opposite claim—that generated code is safe because it is widely used or looks idiomatic—is equally unjustified. Neither the label “AI-generated” nor a high test score is a safety case.
Specific risks include incorrect assumptions about units, timing, concurrency, memory, or hardware interfaces; missing handling for unusual inputs; and reliance on libraries or patterns unsuitable for the target environment. Generated tests can be weak if they merely confirm the implementation’s own assumptions. There can also be licensing, confidentiality, provenance, and cybersecurity questions, depending on the tool, its terms, the input supplied, and the project’s rules.
AI tools may reproduce insecure coding patterns or suggest dependencies that need scrutiny. A safety review should therefore consider security and safety together where their failure modes overlap. For example, unauthorized changes or malformed inputs could affect a safety function. This does not mean every AI-assisted component has a security flaw; it means the normal threat and hazard assessments still apply.
When to use it—and when to avoid it
Whether AI assistance is appropriate depends on the function’s risk, the project’s assurance process, tool limitations, and the team’s ability to verify the output. It may be easier to justify assistance for low-risk scaffolding or test utilities than for code directly controlling a hazardous function, but even low-risk code must be assessed in its system context.
Before adopting a tool, a team can ask:
- Can the organization inspect and understand every proposed change?
- Can generated output be tested against independent, clear requirements?
- Can tool use, versions, inputs, and resulting changes be controlled and documented as needed?
- Are sensitive code or data protected under the tool’s approved use conditions?
- Does the project’s safety plan or applicable standard allow the proposed process, and what evidence does it require?
If the team cannot answer these questions, restricting AI use for the affected function may be prudent until controls are in place. The decision should be documented and revisited when the tool, process, or system changes.
How it compares with conventional development
AI assistance does not create a separate category of software quality. Conventional code can be defective, and AI-generated code can be correct; both require verification. The practical difference is that AI can produce code quickly and at scale, while its rationale and assumptions may be unclear. That can shift effort from typing toward specification, review, testing, and provenance.
Traditional development processes also vary in rigor. Comparing “AI” with “human-written” code alone is less useful than comparing controlled workflows: requirements, reviews, tests, tool qualification or evaluation where relevant, change control, and evidence. A human author may understand the design better, but that understanding only helps if it is captured and checked. An AI tool may help generate test ideas, but the test strategy still needs independent judgment.
Frequently Asked Questions
Can AI-generated code be used in medical devices?
Potentially, but its use must fit the device’s development and risk-management processes and applicable regulatory requirements. The manufacturer remains responsible for demonstrating that the finished device meets those requirements; AI output is not approval or evidence by itself.
Does passing tests make AI-generated code safe?
No. Tests provide evidence about the scenarios they cover, but they may miss untested conditions, incomplete requirements, or faults in the test itself. Safety assurance typically combines multiple forms of verification and analysis.
Should AI-generated code be reviewed line by line?
Review depth should reflect the code’s role and risk. Reviewers need to understand the behavior and interfaces, not merely scan for style. For safety-related changes, the project’s documented review and verification process should determine what is required.
Can AI write safety-critical software without human oversight?
There is no sound basis for treating generated output as independently trustworthy. People and organizations responsible for the device must define requirements, assess risk, verify results, and retain appropriate control of the software lifecycle.
Is AI-generated code less safe than human-written code?
There is no universal answer. Safety depends on the code, the development process, the system context, and the evidence supporting it. AI changes some risks and workflow considerations, but it does not replace sound engineering practice.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.