You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enforcing structured output (c.f. Pydantic) and offload to temporary variables? [design patterns?] #6758
Looking for design patterns for two things that appear to be missing from the OpenCode docs and community discussions.
Background: extracting structured data (e.g., proper names + professions from a page of text, or products + UPCs from a receipt). The conventional engineering solution uses a package like Pydantic to define a structured class, and PydanticAI to feed it into a client API call, with coercion and retries managed behind the scenes:
frompydanticimportBaseModel, Fieldfrompydantic_aiimportAgentclassEmployee(BaseModel):
name: str=Field(description='the name of the individual listed on their employee card')
role: str=Field(description="the functions the individual has permission to perform for salary")
agent=Agent(
"my.favorite.ollama.model",
output_type=Employee,
instructions=('You perform information retrieval to extract verbatim text phrases from unstructured text.'),
)
asyncdefmain():
result=awaitagent.run("Here is a long document of text containing...")
print(result.output)
Question 1: How do I do the same from an OpenCode prompt without writing that code? From a prompt I can ask for structured data, but there is no guarantee the data is structured (ignoring retry mechanisms PydanticAI implements). Is that correct? And is there a pattern to store validated output to an offline file that OpenCode knows to reference later (similar to how @ works for markdown files)?
Question 2: Repeatability. Industrializing "vibe" work means capturing the sequence of tool/MCP executions from a session and exporting it as deterministic code — essentially MCP servlet cartridges with dependency requirements, replayable without the LLM (or with a small one). This also raises a distillation security consideration: create the sequence once, replay without the LLM. Is any of this native to OpenCode, or is there discussion/design patterns anywhere?
If these don't exist as native capabilities, an MCP server implementing them would be valuable; happy to work with a working group on it.
Activity
thdxr commentedon Mar 25, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.