{
    "$schema": "./provider-rules.schema.json",
    "id": "recovery",
    "contextOverflowPatterns": [
        {
            "provider": "openai",
            "patterns": [
                "This model's maximum context length is",
                "tokens\\. However, (?:your messages|you requested)",
                "reduce the length of the messages",
                "Please reduce the length"
            ]
        },
        { "provider": "azure", "patterns": ["content_length_exceeded"] },
        {
            "provider": "google",
            "patterns": [
                "RESOURCE_EXHAUSTED",
                "exceeds the maximum number of tokens",
                "content is too long",
                "request payload size exceeds",
                "input token limit"
            ]
        },
        {
            "provider": "bedrock",
            "patterns": [
                "ValidationException.*token",
                "Input is too long",
                "exceeds the model's maximum"
            ]
        },
        {
            "provider": "mistral",
            "patterns": ["context length exceeded", "maximum number of tokens"]
        },
        { "provider": "openrouter", "patterns": ["context_length_exceeded"] },
        {
            "provider": "anthropic",
            "patterns": [
                "prompt is too long",
                "input is too long",
                "too many tokens",
                "maximum context length"
            ]
        }
    ],
    "contextOverflowRefit": { "marginTokens": 512 },
    "recover": {
        "openai-compatible": [
            {
                "onSignals": [
                    "toolsSchemaConflict",
                    "schemaComplexity",
                    "responseFormatUnsupported"
                ],
                "action": "schemaInSystemPrompt"
            }
        ],
        "vertex": [
            { "onSignals": ["schemaComplexity"], "action": "schemalessJson" }
        ]
    },
    "fieldRejection": {
        "nvidia-nim": {
            "fields": ["chat_template", "reasoning_budget"],
            "keywords": [
                "unsupported",
                "not supported",
                "does not support",
                "unrecognized",
                "unknown field",
                "unknown parameter",
                "unknown argument",
                "invalid field",
                "invalid parameter",
                "invalid argument"
            ],
            "windowChars": 80
        }
    },
    "bedrockInferenceProfiles": {
        "geo": [
            { "match": "^(us|ca)-", "prefix": "us" },
            { "match": "^(eu|il|me|af)-", "prefix": "eu" },
            { "match": "^ap-northeast-[13]$", "prefix": "jp" },
            { "match": "^ap-southeast-[246]$", "prefix": "au" },
            { "match": "^ap-", "prefix": "apac" }
        ],
        "fallback": "global"
    },
    "topicNotes": {
        "contextOverflowPatterns": "Error text that means the request exceeded the context window, by provider, checked in this order (case-insensitive); more specific providers come first.",
        "contextOverflowRefit": "Tokens kept free when fitting max_tokens to a discovered context window: the character-based input estimate and the backend's own framing differ by a few hundred tokens.",
        "recover": "What a provider does after a rejected structured-output request, chosen by error signal (structured-output.json errorSignals): schemaInSystemPrompt retries without response_format and with the schema in the system prompt; schemalessJson retries in JSON mode without the schema (Vertex does this only without tools).",
        "fieldRejection": "NIM: on a 400 whose body names one of fields within windowChars of a keyword (case-insensitive), that field is removed and the request retried once.",
        "bedrockInferenceProfiles": "The Bedrock geography prefix for an AWS region, first match wins; fallback is tried after it. Which ids get retried, and remembering what worked per region, stays code (named hook bedrock.inferenceProfileRetry)."
    }
}
