def shipping_city(payload):
city = payload.get("order", {}).get("shipping", {}).get("city", "")
return city.title()Deterministic line match: flags a line containing `.get(..., {})` immediately followed by another `.get(`.
A `.get(key, {})` whose empty-dict default is fed straight into another `.get(...)`. Missing data at any level silently becomes an empty value.
Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.
def shipping_city(payload):
city = payload.get("order", {}).get("shipping", {}).get("city", "")
return city.title()Deterministic line match: flags a line containing `.get(..., {})` immediately followed by another `.get(`.
@dataclass
class Order:
shipping_city: str
@classmethod
def parse(cls, payload):
shipping = payload["order"]["shipping"]
return cls(shipping_city=shipping["city"])Normalize the input at the boundary into a typed object (a dataclass or pydantic model), or split the lookup into explicit steps that handle the missing case.
Agents reach for empty-dict fallbacks to avoid a `KeyError` on nested payloads they have never seen. Each level hides another schema assumption, and the chain gets more brittle as the schema evolves.
ai-slop/python-chained-dict-get
ai-slop
Deterministic line match: flags a line containing `.get(..., {})` immediately followed by another `.get(`.
A single `.get(key, default)`, chains whose intermediate default is not an empty dict literal, and lookups split across separate statements are not flagged.
Shipped in aislop v0.9.4 as one of four Python verbosity rules drawn from SlopCodeBench (arXiv 2603.24755).