structured-output-parsing
Skill0 starsChanged 6 months agoMITView on GitHub
Parses LLM responses into typed Pydantic models using StructuredLLM, PydanticOutputParser, or manual JSON parsing. Use when an agent must return structured data (e.g. a classification result, extracted entity, or form field set) rather than free-form text.
In this repository65 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/building-agents/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms-full.txtllms.txt
- llms.txtllms.txt
- adding-guardrailsSkill
- agent-health-timeoutSkill
- agent-permission-scopingSkill
- agent-session-isolationSkill
- agent-step-loggingSkill
- agent-supervisor-routerSkill
- agent-telemetrySkill
- async-agent-backgroundSkill
- building-agentsSkill
- building-teamsSkill
- building-toolsSkill
- calendar-scheduling-toolSkill
- callback-tracing-handlerSkill
- chain-of-thought-promptingSkill
- chat-model-configurationSkill
- code-execution-sandboxSkill
- common-agent-patternsSkill
- context-window-managementSkill
- conversation-memorySkill
- conversation-state-dbSkill
- database-query-toolSkill
- document-loadersSkill
- document-rerankingSkill
- email-notification-toolSkill
- embedding-model-ingestionSkill
- fallback-model-chainSkill
- few-shot-injectionSkill
- filesystem-toolSkill
- human-in-the-loopSkill
- hybrid-searchSkill
- inspecting-streamsSkill
- integrating-with-laurenSkill
- json-schema-enforcementSkill
- llm-provider-connectionSkill
- llm-rate-limitingSkill
- long-term-vector-memorySkill
- managing-memorySkill
- migrating-to-lauren-aiSkill
- multi-agent-delegationSkill
- multi-tool-orchestrationSkill
- multi-turn-tool-stateSkill
- output-guardrailsSkill
- plan-and-execute-agentSkill
- prompt-injection-defenseSkill
- prompt-versioningSkill
- rag-pipelineSkill
- react-agent-loopSkill
- response-validation-retrySkill
- rest-api-toolSkill
- securing-agentsSkill
- semantic-cacheSkill
- streaming-response-handlerSkill
- sub-agent-spawningSkill
- system-prompt-templatingSkill
- testing-agentsSkill
- The first 60 shown.
The file
Files
Use
codemap find "SymbolName"to locate any symbol before reading — it gives exact file + line range and is faster than grep across the whole repo.
Structured Output Parsing
Option 1 — StructuredLLM (recommended)
from __future__ import annotations
from pydantic import BaseModel
from lauren_ai import StructuredLLM, LLMConfig
class SentimentResult(BaseModel):
label: str # "positive" | "negative" | "neutral"
score: float
reasoning: str
cfg = LLMConfig.for_anthropic(model="claude-opus-4-6")
llm = StructuredLLM(config=cfg, schema=SentimentResult)
result: SentimentResult = await llm.generate("Analyze: 'I love this product!'")
print(result.label, result.score)StructuredLLM builds a tool schema from the Pydantic model and instructs the
LLM to call it, then deserializes the tool input back into the model.
Option 2 — PydanticOutputParser
from __future__ import annotations
from pydantic import BaseModel
from lauren_ai import PydanticOutputParser, RetryOutputParser
class ProductInfo(BaseModel):
name: str
price: float
in_stock: bool
parser = PydanticOutputParser(model=ProductInfo)
# Wrap with retry for robustness:
retry_parser = RetryOutputParser(parser=parser, max_retries=2)
result = parser.parse('{"name": "Widget", "price": 9.99, "in_stock": true}')Option 3 — Manual JSON parse in an agent
from __future__ import annotations
import json
from pydantic import BaseModel, ValidationError
class ExtractedData(BaseModel):
name: str
count: int
def parse_structured_response(content: str, schema: type[BaseModel]) -> BaseModel:
try:
data = json.loads(content.strip())
return schema.model_validate(data)
except (json.JSONDecodeError, ValidationError) as exc:
raise ValueError(f"Agent output is not valid {schema.__name__}: {exc}") from excTesting with MockTransport
from lauren_ai._transport._mock import MockTransport
mock = MockTransport()
# queue_structured serializes the Pydantic instance as a tool-use completion:
mock.queue_structured(SentimentResult(label="positive", score=0.9, reasoning="Positive tone"))Or queue raw JSON for manual parse tests:
from lauren_ai._transport import Completion, TokenUsage
mock.queue_response(Completion(
id="c1", model="mock-model",
content='{"label": "positive", "score": 0.9, "reasoning": "Great!"}',
tool_calls=[], stop_reason="end_turn",
usage=TokenUsage(input_tokens=10, output_tokens=20),
))Reference files
| File | Contents |
src/lauren_ai/_transport/_structured.py | StructuredLLM implementation |
src/lauren_ai/_output_parsers/ | PydanticOutputParser, RetryOutputParser, etc. |
src/lauren_ai/_transport/_mock.py | queue_structured() helper |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

