For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Help on Discord
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
    • Overview
  • baml-cli
    • init
    • generate
    • test
    • serve
    • dev
    • fmt
  • Language Reference
    • Types
    • function
    • test
    • template_string
    • client<llm>
    • class
    • enum
    • generator
  • Generated baml_client
    • with_options(..)
    • AbortSignal / Cancellation
    • Collector
    • logging / env vars
    • AsyncClient / SyncClient
    • TypeBuilder
    • ClientRegistry
    • client Option
    • OnTick
    • Multimodal
    • Image
    • Audio
    • Pdf
    • Video
      • Overview
      • BamlValidationError
      • BamlClientFinishReasonError
      • BamlAbortError
  • Attributes
    • What are attributes?
    • @alias / @@alias
    • @description / @@description
    • @skip
    • @assert
    • @check
    • Jinja in Attributes
    • @@dynamic
  • LLM Client Providers
    • Overview
    • AWS Bedrock
    • Anthropic
    • Google AI: Gemini
    • Google: Vertex
    • OpenAI
    • OpenAI Responses API
    • OpenAI from Azure
    • OpenRouter
    • openai-generic
    • Microsoft Foundry (openai-generic)
    • Cerebras (openai-generic)
    • Groq (openai-generic)
    • Hugging Face (openai-generic)
    • Keywords AI (openai-generic)
    • Llama API (openai-generic)
    • Litellm (openai-generic)
    • LM Studio (openai-generic)
    • Ollama (openai-generic)
    • Vercel AI Gateway (openai-generic)
    • Tinfoil (openai-generic)
    • TogetherAI (openai-generic)
    • Unify AI (openai-generic)
    • vLLM (openai-generic)
  • LLM Client Strategies
    • Timeout Configuration
    • Retry Policy
    • Fallback
    • Round Robin
  • Prompt Syntax
    • What is jinja?
    • Jinja Filters
    • ctx.output_format
    • ctx.client
    • _.role
    • Variables
    • Conditionals
    • Loops
  • Editor Extension Settings
    • baml.cliPath
    • baml.generateCodeOnSave
    • baml.enablePlaygroundProxy
    • baml.syncExtensionToGeneratorVersion
Help on Discord
LogoLogo
On this page
  • Type Definition
  • Properties
  • Type Guards
Generated baml_clientErrors

BamlClientFinishReasonError

Was this page helpful?
Edit this page
Previous

BamlAbortError

Next
Built with

The BamlClientFinishReasonError class represents an error that occurs when an LLM terminates with a disallowed finish reason.

You can allow or disallow finish reasons like this:

1client<llm> OpenAIWithFinishReasonError {
2 provider openai
3 options {
4 api_key env.OPENAI_API_KEY
5 model "gpt-4"
6 // make it very small so model will stop early
7 max_tokens 10
8 // throws if the model returns any other finish reason
9 finish_reason_allow_list ["stop"]
10 // or allow all finish reasons except length
11 // finish_reason_deny_list ["length"]
12 }
13}

Type Definition

Type Definition
1class BamlClientFinishReasonError extends Error {
2 type: 'BamlClientFinishReasonError'
3 message: string
4 prompt: string
5 raw_output: string
6 detailed_message: string
7}

Properties

type
'BamlClientFinishReasonError'

Literal type identifier for the error class.

message
string

Error message describing the specific finish reason that caused the termination.

prompt
string

The original prompt sent to the LLM.

raw_output
string

The partial output received from the LLM before termination.

detailed_message
string

Comprehensive error information that includes the complete history of all failed attempts when using fallback clients or retry policies. When multiple attempts are made (via fallback or retry), this field contains formatted details about each failed attempt, making it invaluable for debugging complex client configurations.

Type Guards

The error can be identified using TypeScript’s instanceof operator:

Type Check
1if (error instanceof BamlClientFinishReasonError) {
2 // Handle finish reason error
3}