FoundationAgents/MetaGPT · error · JSONDecodeError

Expecting ':' delimiter

Error message

Expecting ':' delimiter

What it means

Raised by MetaGPT's custom decoder (metagpt/utils/custom_decoder.py) while scanning an object: after a key string is consumed, it expects the next significant character to be ':' (optionally after whitespace). If it isn't — a missing colon between key and value — JSONDecodeError('Expecting \'\:\' delimiter') is raised at that position.

Source

Thrown at metagpt/utils/custom_decoder.py:152

                pairs = object_hook(pairs)
            return pairs, end + 1
        elif nextchar != '"':
            raise JSONDecodeError("Expecting property name enclosed in double quotes", s, end)
    end += 1
    while True:
        if end + 1 < len(s) and s[end] == nextchar and s[end + 1] == nextchar:
            # Handle the case where the next two characters are the same as nextchar
            key, end = scanstring(s, end + 2, strict, delimiter=nextchar * 3)
        else:
            # Handle the case where the next two characters are not the same as nextchar
            key, end = scanstring(s, end, strict, delimiter=nextchar)
        key = memo_get(key, key)
        # To skip some function call overhead we optimize the fast paths where
        # the JSON key separator is ": " or just ":".
        if s[end : end + 1] != ":":
            end = _w(s, end).end()
            if s[end : end + 1] != ":":
                raise JSONDecodeError("Expecting ':' delimiter", s, end)
        end += 1

        try:
            if s[end] in _ws:
                end += 1
                if s[end] in _ws:
                    end = _w(s, end + 1).end()
        except IndexError:
            pass

        try:
            value, end = scan_once(s, end)
        except StopIteration as err:
            raise JSONDecodeError("Expecting value", s, err.value) from None
        pairs_append((key, value))
        try:
            nextchar = s[end]
            if nextchar in _ws:

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Look at the colno in the JSONDecodeError; the character right there should be a colon.
  2. Fix the source text: '{"a": 1}', '{"a": 1}'.
  3. For '=' style input, convert it (replace '=' with ':' before decoding) or use a YAML parser.
  4. Increase max_tokens / re-request if truncation cut the JSON mid-object.

Example fix

# before
loads('{"a" 1}')  # missing colon

# after
loads('{"a": 1}')
Defensive patterns

Strategy: try-catch

Validate before calling

import re

def fix_missing_colons(text: str) -> str:
    return re.sub(r'("(?:[^"\\]|\\.)*")\s+(?=["\[\{\d\wtfn])', r'\1:', text)  # heuristic 'key" value' -> 'key": value'

Try / catch

from json import JSONDecodeError
try:
    obj = loads(text)
except JSONDecodeError as e:
    if e.msg == "Expecting ':' delimiter":
        # inspect text at (e.lineno, e.colno); repair '=' or missing ':' and retry

Prevention

When it happens

Trigger: Decoding '{"a" 1}' (colon omitted); '{"a" = 1}' (equals sign, YAML/JS habit); '{"a", "b": 1}' (comma where colon belongs); a truncated string like '{"key"' where the input ends before the colon.

Common situations: LLM writes JS-object or YAML-flavored syntax inside JSON; hand-typed config files with '=' instead of ':'; response truncated by max_tokens right after the key token.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/1e05474e9d230351. Report an issue: GitHub.