fern/snippets/finish-reason.mdx
<ParamField path="finish_reason_allow_list" type="string[]"
Which finish reasons are allowed? Default: null
<Warning>version 0.73.0 onwards: This is case insensitive.</Warning>
Will raise a BamlClientFinishReasonError if the finish reason is not in the allow list. See Exceptions for more details.
Note, only one of finish_reason_allow_list or finish_reason_deny_list can be set.
For example you can set this to ["stop"] to only allow the stop finish reason, all other finish reasons (e.g. length) will treated as failures that PREVENT fallbacks and retries (similar to parsing errors).
Then in your code you can use something like:
client<llm> MyClient {
provider "openai"
options {
model "gpt-5-mini"
api_key env.OPENAI_API_KEY
// Finish reason allow list will only allow the stop finish reason
finish_reason_allow_list ["stop"]
}
}
<ParamField path="finish_reason_deny_list" type="string[]"
Which finish reasons are denied? Default: null
<Warning>version 0.73.0 onwards: This is case insensitive.</Warning>
Will raise a BamlClientFinishReasonError if the finish reason is in the deny list. See Exceptions for more details.
Note, only one of finish_reason_allow_list or finish_reason_deny_list can be set.
For example you can set this to ["length"] to stop the function from continuing if the finish reason is length. (e.g. LLM was cut off because it was too long).
Then in your code you can use something like:
client<llm> MyClient {
provider "openai"
options {
model "gpt-5-mini"
api_key env.OPENAI_API_KEY
// Finish reason deny list will allow all finish reasons except length
finish_reason_deny_list ["length"]
}
}