Maintain deterministic, provider-compatible API contracts by (1) applying overrides explicitly and attempt-scoped (no hidden side effects), and (2) preserving exact request/response serialization expectations—especially where providers are sensitive to JSON schema structure/order or where passthrough/raw modes must not be rewritten.

How to apply:

Example (attempt-scoped override wiring):

preReq := resultFromHooks() // may contain ProviderOverride
ctx.ClearValue(schemas.BifrostContextKeyProviderOverride)
if preReq != nil && preReq.ProviderOverride != nil {
    ctx.SetValue(schemas.BifrostContextKeyProviderOverride, preReq.ProviderOverride)
}

Example (schema contract preserving order):

type ResponsesTextConfigFormatJSONSchema struct {
    Name   *string          `json:"name,omitempty"`
    Schema *OrderedMap     `json:"schema,omitempty"` // preserves JSON key order
}