Skip to content

Enforcing structured output (c.f. Pydantic) and offload to temporary variables? [design patterns?] #6758

Closed as not planned

Description

@davidbernat

Question

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:

from pydantic import BaseModel, Field
from pydantic_ai import Agent

class Employee(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.'),
)

async def main():
    result = await agent.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.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. thdxr commented on Mar 25, 2026

    @thdxr
    Member

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions