FoundationAgents/MetaGPT · error · ValueError
File path is not set.
Error message
File path is not set.
What it means
Document.to_path() writes the document content to disk; it accepts an optional path argument, otherwise using self.path. If neither is set (the Document was created via from_text without a path), it raises ValueError('File path is not set.') because there is nowhere to write. persist() delegates here, so persisting a path-less Document fails the same way.
Source
Thrown at metagpt/document.py:98
content = path.read_text()
return cls(content=content, path=path)
@classmethod
def from_text(cls, text: str, path: Optional[Path] = None):
"""
Create a Document from a text string.
"""
return cls(content=text, path=path)
def to_path(self, path: Optional[Path] = None):
"""
Save content to the specified file path.
"""
if path is not None:
self.path = path
if self.path is None:
raise ValueError("File path is not set.")
self.path.parent.mkdir(parents=True, exist_ok=True)
# TODO: excel, csv, json, etc.
self.path.write_text(self.content, encoding="utf-8")
def persist(self):
"""
Persist document to disk.
"""
return self.to_path()
class IndexableDocument(Document):
"""
Advanced document handling: For vector databases or search engines.
"""
model_config = ConfigDict(arbitrary_types_allowed=True)View on GitHub (pinned to 11cdf466d0)
Solutions
- Pass a destination: doc.to_path(Path('out/docs/note.md')).
- Or set doc.path = Path('out/docs/note.md') before calling persist().
- Create the Document with a path up front: Document(content=text, path=Path('out/note.md')).
Example fix
# before
doc = Document.from_text('hello')
doc.persist() # ValueError: File path is not set.
# after
doc = Document.from_text('hello', path=Path('out/hello.md'))
doc.persist() Defensive patterns
Strategy: validation
Validate before calling
if doc.path is None and target is None:
raise ValueError('refusing to persist: no destination set')
doc.to_path(target or doc.path) Type guard
def has_destination(doc: Document) -> bool:
return getattr(doc, 'path', None) is not None Try / catch
try:
doc.persist()
except ValueError:
doc.to_path(Path('out') / 'untitled.md') Prevention
- Always create Documents with an explicit path when they will be persisted.
- Pass the destination to to_path() in generic save helpers.
- Assert doc.path is not None before calling persist().
When it happens
Trigger: doc = Document.from_text('hello'); doc.persist() or doc.to_path() — no path was ever assigned. Also happens after explicitly setting doc.path = None.
Common situations: Creating documents from LLM output or in-memory strings and forgetting to give them a destination; generic save helpers that call persist() on mixed document sets where some lack paths.
Related errors
- use `revise` after `fill`
- No such attribute: {key}
- File format not supported.
- File {path} not found.
- File {data_path} not found.
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/ac0b88229f3fe0c9.
Report an issue: GitHub.