Why endocrinologists should try coding
Learning to code can help physicians better understand how artificial intelligence (AI) tools work, question their outputs, and recognize errors that could affect patient care, according to Steven Petak, MD, JD, MACE, FACP, past president of AACE and an attorney with a background in computer science.
“AI is arriving in our clinics whether or not we understand it, and the fastest way to demystify something is to take it apart,” he said.
With AI-assisted coding, physicians can describe a task in plain language and ask an assistant to draft the software. The educational value comes from defining what the tool should do, examining its logic, and testing whether its outputs match expectations, according to Dr. Petak. "The goal is literacy, not mastery," he said.
In this Q&A, Dr. Petak explains how to begin coding with a small project using fictional cases, test for mistakes, and recognize when additional expertise is needed. He also addresses patient privacy, medicolegal responsibilities, and the distinction between a working prototype and a tool validated for clinical use.
Q. What do you mean by coding, and how much expertise does a physician need?
Dr. Petak: Not billing codes, fortunately. Both can cause headaches, but only one involves modifier 25. Here, coding means writing instructions that make a computer perform a defined task: organize information, apply a formula, or run an interactive teaching exercise.
A computer program is less mysterious than it sounds. At heart, it is a very literal set of if-then rules, much like a clinical algorithm. The catch is that a computer does exactly what you wrote, not what you meant. As an attorney, I find that familiar; contracts work the same way.
With AI-assisted coding, you describe the task in plain English, and the assistant drafts the program and explains it.1 You do not need software-engineering training to start. You do need to specify the inputs, the expected outputs, and the situations in which the tool should stop. A working prototype is a starting point, not evidence that the software is ready for patient care.
Q. What is actually happening inside an AI tool?
Dr. Petak: It helps to separate two kinds of software. Conventional software follows explicit rules that a person wrote. For deterministic software, the same input gives the same output, like a printed flowchart. When it is wrong, it tends to be wrong the same way every time, which makes errors easier to catch.
A large language model—the engine behind chatbots and AI scribes—works differently. It has been trained on vast amounts of text to predict the next token, a word, or part of a word. The result is remarkably fluent, but fluency is not verification. Unless it is connected to a reliable source, it is not looking anything up; it is producing text that sounds right. When it fills a gap with plausible fiction, that is commonly called a “hallucination.” But I prefer confabulation or fabrication. Clinicians will recognize confabulation. Picture a brilliant student who has read every textbook, has never examined a patient, and is constitutionally unable to say, “I don’t know.”
Most commercial AI products combine the two: a language model wrapped in conventional code and connected to data. The practical lesson is that conventional software tends to fail predictably, while language models can fail persuasively. Building even a small tool lets you see both kinds of failure firsthand, on fictional data, where the stakes are low.
Q. Can you give an example involving an AI scribe?
Dr. Petak: Consider a hypothetical diabetes visit. The AI-drafted note reads smoothly, but it blurs the prescribed insulin regimen with what the patient reports actually taking. That matters medicolegally. Once you authenticate the note, you are responsible for what you attest to, whoever—or whatever—drafted it. Check whether the scribe already offers a suitable template, as not every problem needs new software.
For a teaching prototype, you could build a separate form with fields for prescribed therapy, reported use, glucose units, hypoglycemia history, and follow-up. Enter information by hand from a fictional note. The program organizes the entries and flags missing fields without inventing an assessment or recommending a dose.
Here is the key rule: a blank hypoglycemia field must display “not documented,” never “no hypoglycemia.” Every clinician has heard that if it wasn’t documented, it wasn’t done. The corollary matters just as much—absence of documentation is not documentation of absence. Software that quietly converts one into the other creates a record of a question nobody asked. Here's what that rule looks like in code:
In plain English: If the hypoglycemia field is blank, show “Not documented.”
The same rule in JavaScript, the language web browsers understand (simplified):
if (hypoglycemia === "") {
show("Not documented");
}
The triple equals sign means “is strictly equal to,” and the empty quotation marks mean “nothing was entered.” The punctuation is fussy, but the logic is the same if-then reasoning you use to interpret a dexamethasone suppression test. Now imagine a one-line error that shows “No hypoglycemia” instead. The program runs perfectly. The note is wrong. That is why we test.
Begin with entirely fictional cases and keep the prototype separate from the medical record. Having software automatically interpret the scribe’s narrative would be a far more complex project requiring additional evaluation.
Q. How should a complete beginner get started?
Dr. Petak: Start with a small, low-risk project using entirely fictional cases. Good first projects include a teaching quiz, a summary of a guideline you already know well, a draft patient handout that you review line by line, or a calculator built from a published formula. Many can be finished on a weekend, often faster than prior authorization. An autonomous dosing algorithm is not a first project. Here are four steps to follow:
Choose one task. State exactly what the tool should do, and what it must not do.
Supply the content and rules. Provide your own reviewed material rather than asking AI to invent an endocrine protocol.
Request a simple prototype. Ask for a single web page (an “HTML file”) that opens in your ordinary browser, instructions for opening it, and a plain-language explanation of its logic. Avoid accounts, databases, and connections to clinical systems.
Test before expanding. Write down the expected results for fictional examples before looking at the program’s answers, the software equivalent of not peeking at the answer key. Save a copy of the first working version.
For example, try this prompt:
“Build a single offline HTML page for a diabetes-documentation teaching exercise. Use separate fields for prescribed therapy, reported use, glucose units, hypoglycemia history, and follow-up. Mark blank fields ‘Not documented.’ Do not infer facts, recommend doses, save entries, or contact external services. Explain how to open the file and test each rule.”
These are design requirements, not guarantees. The assistant may not follow every instruction, which is exactly why you test. Have unfamiliar code or installation commands reviewed before running them, and do not give a coding assistant access to clinical folders.1
Q. What is a sensible intermediate step?
Dr. Petak: Add structured inputs, clear error messages, and repeatable tests. For a formula-based teaching calculator, display the equation, source, units, and limitations, and compare results with independently calculated answers. Then try to break it: enter missing or impossible values, mismatched units, and values at, just above, and just below every cutoff. Computers, like the rest of us, are easily confused by “greater than or equal to.”
Units deserve special respect. For instance, a glucose of 7 is unremarkable in mmol/L and an emergency in mg/dL. A program given the wrong units will produce a wrong answer with complete confidence, much like a thyroid panel drawn on a patient taking high-dose biotin: precise-looking numbers, wrong conclusion. Programmers call this “garbage in, garbage out.”
Importantly, using AI to write software does not mean AI must remain inside the finished tool. A fixed-rule checklist can run without sending each entry to a language model. That does not eliminate coding errors, but it makes the rules easier to inspect, keeps the behavior consistent, and avoids sending entries to an outside service. Keep a dated change log and a copy of each tested version.
Q. What should you do when you get stuck, or want to add features?
Dr. Petak: Reduce the problem to the smallest failing example: “When this field is blank, I expect ‘not documented,’ but the program reports ‘normal.’” Give the assistant that fictional input, the expected result, and the actual result, and ask for that specific correction. Asking an AI to “fix everything” is like ordering a “full endocrine workup”—you will get a lot of results and not necessarily an answer.
Then rerun all previous tests, not just the one that failed. Fixing one problem can quietly create another. AI-generated tests can help, but they do not replace independent review.1 Ask a colleague to try confusing inputs and challenge your assumptions. A second AI agreeing with the first is not clinical validation. It is a curbside consult with someone who read the same textbook.
Add one feature at a time, only when it addresses a defined need, and recheck the logic, units, privacy implications, and earlier results. Changes that add treatment recommendations or real patient data deserve a new clinical, technical, and compliance review, not merely another version number.
Q. Where are the medicolegal boundaries?
Dr. Petak: Protect patient information. Removing a name is not HIPAA de-identification. An unusual detail, such as a rare genetic variant in a small town, can still identify someone. HIPAA provides specific Safe Harbor and Expert Determination methods.2 Use fictional cases while learning and keep protected health information out of unapproved tools.
For a HIPAA-covered practice, an outside service that handles electronic protected health information on its behalf generally requires a business associate agreement (BAA) and appropriate safeguards. A BAA is a contract, not a clinical validation, and it does not mean the data stay on your laptop. Use such AI services only under the required BAA and safeguards. Review data flows, access, storage, and permitted uses with your privacy and security team.3
Cybersecurity is part of the job. Ransomware does not care that your tool was a weekend project. Federal guidance treats ransomware encryption of protected health information as a presumed breach unless the practice can demonstrate a low probability that the information was compromised.4 A homemade tool that stores patient data can become an unplanned entry point, which is another reason to begin offline with fictional cases.
FDA oversight depends on the software’s function and intended use. Some clinical decision support functions are excluded from the device definition, while others remain subject to oversight.5 Software that analyzes medical images or physiologic signals, or does not let the clinician independently review the basis for its recommendations, can fall outside the non-device Clinical Decision Support exclusion and may be regulated as a device. Some states also regulate AI-generated patient communications. Requirements vary by jurisdiction, so check your state’s rules.
Before any clinical deployment, involve appropriate institutional, technical, and regulatory reviewers. Discuss responsibility, contracts, and insurance coverage with counsel and your malpractice insurer, especially before sharing a tool with others. Decide who checks outputs, maintains the software, monitors its performance, and can withdraw it from use.
Finally, testing that a program runs is different from validating its clinical performance. “The AI wrote it” is not a validation protocol, and “the computer said so” has rarely impressed a jury.
Q. Is it enough to remain a well-informed user?
Dr. Petak: Absolutely. The goal is literacy, not mastery. Not every endocrinologist needs to build software, just as not every endocrinologist needs to run an immunoassay laboratory. But knowing how the assay works makes you much better at spotting an implausible result, and a small, hands-on experiment does the same for AI. Begin with a useful teaching tool, keep patient data out, and learn to question the result. We should be curious about these tools without confusing curiosity with clinical readiness.
References
1. GitHub. Application card: GitHub Copilot Chat. GitHub Docs. Sections on capabilities, limitations, and responsible use. Accessed September 28, 2026.
2. US Department of Health and Human Services. Guidance Regarding Methods for De-identification of Protected Health Information in Accordance with the Health Insurance Portability and Accountability Act (HIPAA) Privacy Rule. Reviewed February 3, 2025.
3. US Department of Health and Human Services. Guidance on HIPAA & Cloud Computing. Reviewed December 23, 2022.
4. US Department of Health and Human Services, Office for Civil Rights. Fact Sheet: Ransomware and HIPAA. July 11, 2016.
5. US Food and Drug Administration. Clinical Decision Support Software: Guidance for Industry and Food and Drug Administration Staff. Issued January 6, 2026; reissued January 29, 2026.
AACE Endocrine AI is published by Conexiant under a license arrangement with the American Association of Clinical Endocrinology, Inc. (AACE®). The ideas and opinions expressed in AACE Endocrine AI do not necessarily reflect those of Conexiant or AACE. For more information, see Policies.