Do not infer every familiar chat schema is compatible
Some clients send content as an array of text blocks, add name fields or include tool-call metadata. Those patterns are outside this customer's documented contract even if another endpoint supports them. System instructions guide the task, but they are not a secure place for secrets that must never appear in model context.
What to do next
- 01
Validate each message object
Allow only role and content, confirm a supported role, and reject empty or non-string content before the network call. Keep the total message and byte limits in view.
- 02
Separate user and application text
Place application instructions and user requests deliberately rather than relabeling untrusted content as system policy. Keep prior assistant output identifiable when including conversation history.
- 03
Quote the final array
Use the exact validated messages for estimation and creation. If the user edits the conversation before submission, treat that as changed input and review the new quote.
A concrete example
Illustrative mismatch: an SDK sends content:[{type:text,text:Hello}]. The current route expects content as a plain string. Convert the supported text deliberately rather than forwarding the entire SDK object or silently dropping it.
Before you call it ready
- Every message uses a supported role.
- Content is a non-empty string.
- The payload includes an actual user message.
When to stop or choose another method
If your workflow requires tool messages or multimodal blocks, stop and choose a contract that supports them. Flattening them blindly can lose meaning and produce misleading answers.
