Add appended message request validation

This commit is contained in:
2026-08-26 02:10:01 +00:00
parent 5064cf833d
commit ed0f7527d5
9 changed files with 277 additions and 24 deletions

View File

@@ -123,6 +123,13 @@ type RunRequest struct {
// Validation optionally replaces the prompt's complete output contract. It
// does not merge individual fields. Nil uses the prompt contract.
Validation *OutputContract
// AppendedMessages are already-rendered messages appended after every prompt
// definition message. Promptkit neither templates nor resolves files in
// them, and preserves valid content exactly. Nil and empty slices are
// equivalent. Prepare, PrepareExecution, and Run validate and copy the
// messages before source or model work; malformed values return an error
// matching ErrInvalidRequest.
AppendedMessages []RenderedMessage
}
// PreparedRun contains prepared prompt execution state returned by
@@ -629,12 +636,13 @@ type RenderedPrompt struct {
Messages []RenderedMessage `json:"messages"`
}
// RenderedMessage is a rendered chat message and has a stable JSON
// representation.
// RenderedMessage is a prepared, provider-bound text chat message and has a
// stable JSON representation. Its role must be one of [RoleDeveloper],
// [RoleSystem], [RoleUser], or [RoleAssistant].
type RenderedMessage struct {
// Role is the definition-supplied chat role.
// Role is the provider-bound chat role.
Role string `json:"role"`
// Content is the rendered message text.
// Content is the provider-bound message text and may be empty or whitespace.
Content string `json:"content"`
// CacheControl is optional provider cache metadata.
CacheControl *CacheControl `json:"cache_control,omitempty"`