Repository navigation
Commit c28d64d
authored
Python: fix(bedrock): map guardrail_intervened and model_context_window_exceeded stop reasons (#14631)
### Motivation and Context
The Bedrock Converse API can end a turn with `guardrail_intervened` (a
configured guardrail blocked the output) or
`model_context_window_exceeded` (the model hit its context window).
`finish_reason_from_bedrock_to_semantic_kernel` only knew five of the
stop reasons, so for these two the message came back with
`finish_reason=None`, indistinguishable from an unrecognised value.
### Description
- `guardrail_intervened` maps to `FinishReason.CONTENT_FILTER`, same as
`content_filtered`.
- `model_context_window_exceeded` maps to `FinishReason.LENGTH`, same as
`max_tokens`.
- Unit tests for both mappings; they fail on `main` (the function
returns `None`) and pass with the change. The Bedrock unit test folder
passes.
### Contribution Checklist
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the SK Contribution Guidelines
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
This change was made with Claude Code; the tests were run against `main`
and the branch.1 parent 2ebeb95 commit c28d64d
2 files changed
Lines changed: 14 additions & 0 deletions
File tree
- python
- semantic_kernel/connectors/ai/bedrock/services/model_provider
- tests/unit/connectors/ai/bedrock/services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
216 | 218 | | |
217 | 219 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
347 | 359 | | |
348 | 360 | | |
349 | 361 | | |
| |||
0 commit comments