Blog

    ChatGPT API Parameters for Clinical Text: Temperature, Token Limits and Stop Sequences on Any LLM API

    By GauravSeptember 8, 20269 mins read
    On this page

    ChatGPT API parameters, and the matching settings on other LLM APIs, decide how a model behaves on clinical text: how varied its wording is, how long it may write, where it stops and what shape the answer takes. The names differ between vendors, but the decisions behind them are the same.

    Startup founders and engineering leaders building features that summarise, extract or draft from clinical text will find what each parameter does, settings that suit clinical tasks, how to read why a response stopped, and what must not be sent or logged.

    Which ChatGPT API parameters matter most for clinical text?

    The ChatGPT API parameters that matter most for clinical text are temperature, the output token limit, stop sequences and structured output, and other LLM APIs offer close equivalents. Agnotic Technologies sets them per task, checks the stop reason on every response and keeps them in versioned configuration so a clinical feature behaves the same after each deploy.

    Adding an LLM feature that reads clinical text?

    We choose the parameters per task, handle every stop reason and keep PHI rules in code.

    OpenAI's Chat Completions reference gives temperature a range of 0 to 2 with a default of 1 and recommends altering temperature or top_p but not both. It allows up to 4 stop sequences and notes the stop parameter is not supported with the o3 and o4-mini reasoning models.

    What does temperature change, and what suits clinical tasks?

    Temperature changes how much randomness the model uses when choosing each next token. Low values make output more repeatable and high values make it more varied, which is rarely what an extraction or a summary of a patient record needs.

    Starting points by clinical task
    TaskTemperatureWhy
    Extracting medications or problems into fieldsThe lowest the model allowsThe same note should give the same fields
    Summarising a discharge note for a clinicianLowWording may vary slightly; facts must not
    Drafting patient instructions for staff reviewLow to moderateSome variety in phrasing is acceptable
    Classifying a message for routingThe lowest the model allowsRouting must be repeatable and testable

    Low temperature does not make output correct, only more consistent. A consistent wrong answer is easier to find in testing, which is the real benefit.

    Change temperature or top_p, not both, and never assume a setting carries over to a new model. Models differ in which parameters they accept, so check the reference for each model before you deploy it.

    How should you set the output token limit?

    Set the output token limit from the longest valid answer for the task plus a margin, and treat any response that hits it as incomplete. A cut-off summary can drop the last items in a list, which in clinical text may be the most recent medication or result.

    The same OpenAI reference lists finish_reason values that include stop, for a natural end or a matched stop sequence, length, when the response hit the token limit set in the request, and content_filter, when content was omitted by a filter.

    Anthropic's guide to stop reasons lists end_turn, max_tokens, stop_sequence, tool_use and refusal among the stop_reason values a response can carry, and recommends raising max_tokens or continuing the response when it stopped at the max_tokens limit.

    • Measure the longest expected output on test cases, then set the limit above it.
    • Never show a response that stopped on the length limit as if it were complete.
    • Retry once with a shorter input or a higher limit, then fall back to no output and a clear message.
    • Count the input too: a long record can fill the context window before the answer starts.

    When are stop sequences useful?

    Stop sequences are useful when the output has a known end marker, such as a closing tag in a template, and generation should end there. They matter less when structured output already defines where the answer ends.

    • Pick a stop sequence that cannot occur in clinical text itself, such as a dedicated marker string.
    • Check the stop reason: a response that ended on a stop sequence is different from one that ended naturally.
    • Confirm the model supports stop sequences at all, since some reasoning models do not.

    How does structured output fit with these parameters?

    Structured output constrains the response to a JSON schema you supply, which removes most parsing failures but not wrong values. It works alongside low temperature and a sensible token limit, not instead of them.

    • Give each extracted item its own field, plus an evidence quote the app can check against the source text.
    • Validate the object in code after the call, including rules the schema cannot express.
    • Treat a refusal or a length stop as no result, never as an empty list.

    What must not be sent to an LLM API or logged?

    Send only the minimum text the task needs, and only to an API account covered by a business associate agreement and settings your compliance lead has approved. Agnotic strips identifiers the task does not use before the call and keeps prompts and responses out of general application logs.

    • Do not send a whole record when the task needs one note or one section.
    • Do not send names, record numbers, addresses or other direct identifiers unless the task needs them.
    • Do not write prompts or responses that contain PHI to general logging, analytics or error tracking tools.
    • Do keep an audit record of each call with the model, parameters, prompt version and a reference to the source document, protected like the record itself.
    • Do check the data retention and training settings of the vendor account the app uses.

    How do you keep parameters consistent across deploys?

    Keep parameters in versioned configuration next to the prompt, and record the version on every call. A clinical feature whose temperature or model changes silently cannot be compared with its own test results.

    • One configuration per task: model name and version, temperature, token limit, stop sequences and schema version.
    • Every change goes through review and a run of the task's test set before deploy.
    • Each logged call carries the configuration version, so a bad output can be traced to its settings.

    How should one configuration map to different vendors?

    Map one internal configuration per task onto each vendor's parameter names and ranges in a thin adapter layer. The rest of the application then asks for a task, not for a vendor's settings.

    One internal setting, different vendor names
    Internal settingWhat the adapter handles
    Randomness levelThe vendor's temperature range and whether the model accepts it
    Maximum outputThe vendor's token limit parameter name and model maximum
    End markerStop sequence support and how many sequences are allowed
    Why it stoppedfinish_reason or stop_reason values mapped to complete, truncated, refused or failed

    What should the test set for each task contain?

    Each task's test set should hold the cases that trip models up on clinical text, not only typical notes, and a clinician should agree the expected output for every case before any parameter is tuned.

    • Typical documents of the length and style your users actually produce.
    • Long documents near the input limit, to catch truncation and context overflow.
    • Negations and historical mentions, such as a medication stopped last year or a ruled-out diagnosis.
    • Documents with nothing to extract, where the correct answer is an empty result.
    • Abbreviations and local shorthand used at your sites.

    What are the common mistakes with LLM API parameters on clinical text?

    The common mistakes with LLM API parameters on clinical text leave settings at their defaults or ignore what the response says about how it ended.

    • Leaving temperature at the default for extraction tasks.
    • Ignoring the stop reason and showing truncated output.
    • Setting a huge token limit to avoid truncation, which raises cost and latency and hides prompts that produce rambling answers.
    • Changing temperature and top_p together, then not knowing which caused a change.
    • Logging full prompts with patient text to a shared logging service.
    • Assuming parameters behave the same after switching model or vendor.

    A worked example: extracting medications from a discharge summary

    A care coordination app extracts the discharge medication list so a nurse can reconcile it. The call sends only the medication section, uses the lowest temperature the model accepts, and asks for one entry per medication with an evidence quote.

    On a long summary the response stops on the token limit. The app reads the stop reason, shows no list, and retries with the section split in two. Both halves return complete; the app merges them and checks every evidence quote appears in the source before the nurse sees the list.

    What do LLM API parameters mean for your build plan?

    Treat parameters as part of the feature's specification, decided per task against a test set, rather than defaults left in an SDK call. Plan time to build that test set with a clinician.

    • List each LLM task and the output shape it must return.
    • Build a test set per task from synthetic or de-identified text, and agree what counts as a pass.
    • Agree the PHI rules, vendor agreement and logging design before the first call with real data.
    • Plan how a model or vendor change will be tested before it reaches users.

    How does Agnotic build LLM features on clinical text?

    Agnotic builds the call layer with per-task parameters, stop-reason handling, schema validation and versioned configuration, and designs the PHI boundaries around it. We work with whichever LLM vendor the client chooses and test each change against the client's own cases.

    Parameters set per task, not left at defaults

    We build the call layer, the checks and the PHI boundaries around it.

    Sources

    Frequently Asked Questions

    Do not rely on it. Low temperature makes output much more consistent, but tests should check the content of each answer rather than expect the exact same wording every time.

    Talk to an engineer about your project

    Describe one clinical text task and the output you need. We will propose the parameters, the checks and the PHI boundaries.

    Go deeper

    Services and solutions on this topic