FoundationAgents/MetaGPT · error · ValueError
Field '{self.field_name}' not found in object: {obj_dict}
Error message
Field '{self.field_name}' not found in object: {obj_dict} What it means
After successfully parsing obj_json, ObjectSortPostprocessor checks that the configured field_name exists in the decoded object dict; if the sort field is absent it raises this ValueError showing the full object. The ranker sorts by metadata[field_name], so a missing field makes sorting impossible.
Source
Thrown at metagpt/rag/rankers/object_ranker.py:52
if query_bundle is None:
raise ValueError("Missing query bundle in extra info.")
if not nodes:
return []
self._check_metadata(nodes[0].node)
sort_key = lambda node: json.loads(node.node.metadata["obj_json"])[self.field_name]
return self._get_sort_func()(self.top_n, nodes, key=sort_key)
def _check_metadata(self, node: ObjectNode):
try:
obj_dict = json.loads(node.metadata.get("obj_json"))
except Exception as e:
raise ValueError(f"Invalid object json in metadata: {node.metadata}, error: {e}")
if self.field_name not in obj_dict:
raise ValueError(f"Field '{self.field_name}' not found in object: {obj_dict}")
def _get_sort_func(self):
return heapq.nlargest if self.order == "desc" else heapq.nsmallest
View on GitHub (pinned to 11cdf466d0)
Solutions
- Align field_name with an existing key: inspect json.loads(nodes[0].metadata['obj_json']).keys() and use that key
- Re-index objects that all contain the sort field, or filter heterogeneous nodes before the ranker
- Add the field with a default value during ingestion if it is genuinely optional
Example fix
// before ranker = ObjectSortPostprocessor(field_name="cost", top_n=3) # objects have "price" // after ranker = ObjectSortPostprocessor(field_name="price", top_n=3)
Defensive patterns
Strategy: validation
Validate before calling
import json
obj = json.loads(nodes[0].node.metadata["obj_json"])
if ranker.field_name not in obj:
raise ValueError(f"sort field '{ranker.field_name}' not in object keys {sorted(obj)}") Type guard
import json
def objects_have_field(nodes, field_name: str) -> bool:
return all(field_name in json.loads(n.node.metadata.get("obj_json", "{}")) for n in nodes) Try / catch
try:
nodes = ranker.postprocess_nodes(nodes, query_bundle=qb)
except ValueError as e:
if "not found in object" in str(e):
# inspect keys and rebuild ranker with an existing field
keys = sorted(json.loads(nodes[0].node.metadata["obj_json"]).keys())
raise ValueError(f"pick field_name from {keys}") from e
raise Prevention
- Derive field_name from the data: json.loads(obj_json).keys() at config time
- Keep one object schema per index, or filter heterogeneous nodes before ranking
- Re-index after any rename of the sort field
When it happens
Trigger: Constructing ObjectSortPostprocessor(field_name="price") but the indexed objects' obj_json contains no "price" key; renaming a field in the data model without re-indexing; heterogeneous objects in one index where only some carry the field.
Common situations: Field name typo between the ranker config and the ingested data; schema drift after re-generating objects; mixing object types in a single index.
Related errors
- Invalid object json in metadata: {node.metadata}, error: {e}
- Missing __module_class_name field
- Content column not found in DataFrame.
- File format not supported.
- File {data_path} not found.
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/b70333a0181067b9.
Report an issue: GitHub.