From c8b717697857b840b5b23ff8b3d10b359c5c430f Mon Sep 17 00:00:00 2001 From: dwrz Date: Sun, 11 Oct 2026 11:07:41 +0000 Subject: [PATCH] Add llm message validate --- internal/llm/llm.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/llm/llm.go b/internal/llm/llm.go index 298cac6..6d965be 100644 --- a/internal/llm/llm.go +++ b/internal/llm/llm.go @@ -4,6 +4,7 @@ package llm import ( "encoding/json/v2" + "fmt" "strings" ) @@ -524,6 +525,16 @@ func (m *Message) Text() string { return b.String() } +// Validate checks conformance to the OpenAI API specification. +func (m *Message) Validate() error { + if len(m.ToolCalls) != 0 && m.Role != RoleAssistant { + return fmt.Errorf( + "%q message with tool calls", m.Role, + ) + } + return nil +} + // UnmarshalJSON decodes a message while normalizing a string-valued content // field to one text ContentPart. An array-valued content field is decoded in // order. If reasoning_content is absent, reasoning is copied into