{"record":{"id":"d50db9ec8261be53","repo":"BerriAI/litellm","slug":"context-management-compact-20260112-trigger-value","errorCode":null,"errorMessage":"context_management.compact_20260112.trigger.value must be at least {COMPACT_MIN_TRIGGER_TOKENS} tokens","messagePattern":"context_management\\.compact_20260112\\.trigger\\.value must be at least (.+?) tokens","errorType":"validation","errorClass":"AnthropicContextManagementError","httpStatus":400,"severity":"error","filePath":"litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py","lineNumber":562,"sourceCode":"    \"\"\"\n    warnings: Final[list[str]] = []\n    trigger: Final = edit_spec.get(\"trigger\") or {}\n    if not isinstance(trigger, dict):\n        warnings.append(\"trigger_not_a_dict_using_default\")\n        return COMPACT_DEFAULT_TRIGGER_TOKENS, warnings\n\n    trigger_type: Final = trigger.get(\"type\", \"input_tokens\")\n    if trigger_type != \"input_tokens\":\n        warnings.append(f\"unsupported_trigger_type_{trigger_type}_using_input_tokens\")\n\n    value: Final = trigger.get(\"value\")\n    if value is None:\n        return COMPACT_DEFAULT_TRIGGER_TOKENS, warnings\n    if not isinstance(value, int):\n        warnings.append(\"trigger_value_not_int_using_default\")\n        return COMPACT_DEFAULT_TRIGGER_TOKENS, warnings\n    if value < COMPACT_MIN_TRIGGER_TOKENS:\n        raise AnthropicContextManagementError(\n            status_code=400,\n            message=(\n                f\"context_management.compact_20260112.trigger.value must be at \"\n                f\"least {COMPACT_MIN_TRIGGER_TOKENS} tokens\"\n            ),\n        )\n    return value, warnings\n\n\ndef _build_summary_prompt(edit_spec: Mapping[str, object], tools: Sequence[Mapping[str, object]] | None) -> str:\n    custom: Final = edit_spec.get(\"instructions\")\n    if isinstance(custom, str) and custom.strip():\n        return custom\n    prompt = COMPACT_DEFAULT_INSTRUCTIONS\n    if tools:\n        prompt = f\"{prompt}{COMPACT_NO_TOOL_CALLS_SUFFIX}\"\n    return prompt\n","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py#L544-L580","documentation":"Raised by the in-gateway context_management polyfill when validating the compact_20260112 edit specification. The trigger threshold ('context_management.compact_20260112.trigger.value') must be an int of at least 50,000 tokens (COMPACT_MIN_TRIGGER_TOKENS); smaller values are rejected outright rather than clamped, because too-low thresholds would fire compaction constantly. Non-int values get a warning and fall back to the 150,000 default instead.","triggerScenarios":"Sending an Anthropic /v1/messages request with context_management={\"edits\": [{\"type\": \"compact_20260112\", \"trigger\": {\"value\": 10000}}]} — any int below 50,000. Note float values like 50000.0 hit the 'not int' warning path instead and use the default.","commonSituations":"Developers testing compaction with small token counts to force it to trigger; porting configs from providers with lower compaction thresholds; assuming the value is a percentage or a ratio rather than an absolute token count.","solutions":["Set trigger.value to an int >= 50,000, e.g. 50_000 is the minimum accepted.","For local testing of compaction, you cannot lower the threshold; instead send a long conversation that exceeds it.","Omit trigger entirely to accept the 150,000 default.","Keep the value a plain int (not a float or string) or the default is silently used with a warning."],"exampleFix":"# before\ncontext_management = {\n    \"edits\": [{\"type\": \"compact_20260112\", \"trigger\": {\"type\": \"input_tokens\", \"value\": 5000}}]\n}\n\n# after\ncontext_management = {\n    \"edits\": [{\"type\": \"compact_20260112\", \"trigger\": {\"type\": \"input_tokens\", \"value\": 50000}}]\n}","handlingStrategy":"validation","validationCode":"COMPACT_MIN_TRIGGER_TOKENS = 50_000\n\ndef validate_compact_trigger(trigger: dict) -> int:\n    value = trigger.get(\"value\", 150_000)\n    if not isinstance(value, int) or isinstance(value, bool):\n        return 150_000  # gateway will warn and use default\n    if value < COMPACT_MIN_TRIGGER_TOKENS:\n        raise ValueError(f\"trigger.value must be >= {COMPACT_MIN_TRIGGER_TOKENS}\")\n    return value","typeGuard":"def is_valid_compact_trigger(trigger: object) -> bool:\n    if not isinstance(trigger, dict):\n        return False\n    v = trigger.get(\"value\")\n    return v is None or (isinstance(v, int) and not isinstance(v, bool) and v >= 50_000)","tryCatchPattern":"try:\n    resp = litellm.anthropic_messages(**body)\nexcept Exception as e:\n    if \"must be at least\" in str(e) and \"trigger.value\" in str(e):\n        body[\"context_management\"][\"edits\"][0][\"trigger\"][\"value\"] = 50_000\n        resp = litellm.anthropic_messages(**body)\n    else:\n        raise","preventionTips":["Treat trigger.value as an absolute token count, never a percentage.","Never try to force compaction in tests via a tiny threshold — build a long conversation instead.","Keep the value a plain int; floats silently fall back to the 150k default."],"tags":["anthropic","context-management","compaction","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}