ai-amazon-bedrock: a tool result that isn't a JSON object fails the next request

Aperta Adatta ai principianti
#10,766 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@effect-bot ci sta già lavorando.

Dal 19/11/2026.

  • #10767 di @effect-bot — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
79/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Inizia leggendo AmazonBedrockLanguageModel.ts e la funzione toolResultContent indicata nell’issue. Verifica se esistono già test che coprono i risultati degli strumenti Bedrock e confronta come @effect/ai-anthropic gestisce i risultati non stringa. Il lavoro è completato quando i risultati degli strumenti di tipo array e primitivo possono essere inviati in una richiesta Bedrock successiva senza l’errore di convalida segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What happens

When a tool's result is an array (or a number, boolean or null), the next request to Bedrock fails:

AiError: AmazonBedrockClient.converseStream: Invalid request. ValidationException: The format of the value at messages.6.content.1.toolResult.content.0.json is invalid. Provide a json object for the field and try again.

The result stays in the conversation's history, so every later request in that conversation fails the same way.

Reproduction

import { Effect, Schema } from "effect"
import { LanguageModel, Tool, Toolkit } from "effect/ai"

const Search = Tool.make("search", {
  parameters: Schema.Struct({ query: Schema.String }),
  success: Schema.Array(Schema.String)
})

const Tools = Toolkit.make(Search)

const ToolsLive = Tools.toLayer({ search: () => Effect.succeed([]) })

// With AmazonBedrockLanguageModel (Claude via Converse): the model calls `search`,
// and the request that sends its result back fails with the ValidationException above.

Cause

toolResultContent in AmazonBedrockLanguageModel.ts sends every non-string result as json:

const toolResultContent = (result: unknown) => {
  if (typeof result === "string") return [{ text: result }]
  if (Predicate.isUndefined(result)) return [{ text: "" }]
  return [{ json: result }]
}

Converse only accepts a JSON object in ToolResultContentBlock.json. Tool allows any success schema, and @effect/ai-anthropic already handles this by stringifying non-string results.

Suggested fix

Send only objects as json and stringify everything else:

const toolResultContent = (result: unknown) => {
  if (Predicate.isString(result)) return [{ text: result }]
  if (Predicate.isUndefined(result)) return [{ text: "" }]
  if (Predicate.isObject(result)) return [{ json: result }]
  return [{ text: JSON.stringify(result) }]
}

Version: @effect/ai-amazon-bedrock 4.1.4.

Lingua principale
TypeScript
Stelle
16.7k
Fork
808
Merge medio
20h 31m
PR unite (30g)
733

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Effect-TS/effect

Tutte le issue di Effect-TS/effect

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.