[BUG] Unrecognized limits keys are silently ignored, leaving the agent uncapped
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
SDK Language
Python
Strands Version
1.56.0 (reproduced on current main, 45c2ffd3)
Language Runtime Version
Python 3.14.5
Operating System
macOS 15
Installation Method
pip
Steps to Reproduce
limits validation checks only the values of the three recognized keys. A mistyped or misremembered cap name passes validation silently and applies no limit, so the caller believes the loop is bounded when nothing is enforced. Key names from other agent frameworks (max_turns, max_tokens) make this an easy mistake to carry over.
import asyncio
from collections.abc import AsyncGenerator
from typing import Any
from strands import Agent, tool
from strands.models import Model
class PersistentWrongToolModel(Model):
"""Always requests a nonexistent tool, so the loop only stops if a cap fires."""
def __init__(self) -> None:
self.call_count = 0
def get_config(self) -> Any:
return {}
def update_config(self, **model_config: Any) -> None:
pass
async def structured_output(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Any, None]:
yield {}
async def stream(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Any, None]:
self.call_count += 1
if self.call_count > 10:
raise RuntimeError("loop still running after 10 model calls")
yield {"messageStart": {"role": "assistant"}}
yield {"contentBlockStart": {"start": {"toolUse": {"name": "does_not_exist", "toolUseId": f"t{self.call_count}"}}}}
yield {"contentBlockDelta": {"delta": {"toolUse": {"input": "{}"}}}}
yield {"contentBlockStop": {}}
yield {"messageStop": {"stopReason": "tool_use"}}
@tool
def real_tool() -> str:
"""A tool that exists."""
return "ok"
async def main() -> None:
model = PersistentWrongToolModel()
agent = Agent(model=model, tools=[real_tool], callback_handler=None)
result = await agent.invoke_async("go", limits={"turns": 3})
print(f"limits={{'turns': 3}}: stop_reason={result.stop_reason}, model calls={model.call_count}")
model = PersistentWrongToolModel()
agent = Agent(model=model, tools=[real_tool], callback_handler=None)
try:
await agent.invoke_async("go", limits={"max_turns": 3})
except Exception as error:
print(f"limits={{'max_turns': 3}}: {type(error).__name__}: {error} (model calls={model.call_count})")
asyncio.run(main())
Output:
limits={'turns': 3}: stop_reason=limit_turns, model calls=3
limits={'max_turns': 3}: EventLoopException: loop still running after 10 model calls (model calls=11)
No error and no warning is emitted for the max_turns variant. The loop runs uncapped (the RuntimeError above is the repro script's own guard, not the SDK stopping).
Expected Behavior
An unrecognized key in limits raises TypeError, the same way _validate_limits already rejects invalid values ({"turns": 0}, {"turns": -1}, {"turns": True}). The docstring of _validate_limits gives the rationale for rejecting booleans as preventing values that would be "silently no-op'ing or tripping immediately". An unrecognized key silently no-ops the same way, on a construct whose whole purpose is to be a guardrail against runaway loops and token spend.
Actual Behavior
The unrecognized key passes validation, no cap is applied, nothing is logged or raised. The agent loop runs unbounded while the caller believes it is capped at 3 turns.
Additional Context
Root cause: _validate_limits in strands-py/src/strands/agent/agent.py iterates only the three recognized keys (for key in ("turns", "output_tokens", "total_tokens")) and never inspects the keys actually present in the dict.
The TypeScript SDK has the identical gap: _validateLimits in strands-ts/src/agent/agent.ts asserts only limits.turns, limits.outputTokens, and limits.totalTokens, so { limits: { maxTurns: 3 } } is silently uncapped for JavaScript callers and for options objects built dynamically (TypeScript's excess-property check only catches inline literals).
Static typing narrows but does not close the hole in Python either: Limits is a TypedDict, so mypy flags a mistyped literal, but many applications don't run mypy, and caps loaded from config files or built dynamically bypass it entirely. Runtime validation already exists for exactly this reason (the bool rejection guards a case the type system allows).
History note: the feature request that led to limits (#2124) proposed the names max_turns and max_token_budget, and the shipped keys are turns / total_tokens, so the mistyped-vocabulary case is not hypothetical.
Possible Solution
Reject unrecognized keys with TypeError, consistent with the existing value validation. I have this implemented with regression tests in both SDKs and am opening the PRs alongside this issue. If raising is considered too strict for a patch release, the conservative alternative is a warnings.warn (Python) / thrown-vs-logged warning (TypeScript) following the validate_config_keys convention used for unknown model-config keys, though for a budget cap a hard error seems safer than a warning that can scroll past while the loop burns tokens.
Related Issues
#2124 (the original feature request, which used the max_turns vocabulary), #4268 (an example of the unbounded-loop scenario limits exists to contain)