-
Notifications
You must be signed in to change notification settings - Fork 5
Baml structured outputs vercel #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: batch-exec
Are you sure you want to change the base?
Conversation
Greptile OverviewGreptile SummaryThis PR integrates BAML (Boundary ML) structured output extraction using the Vercel AI SDK. The implementation adds the ability to extract structured data from LLM responses by converting JSON schemas to BAML types, rendering prompts with BAML's template system, and parsing responses using BAML's SAP (Schema-Aligned Parsing). Key Changes:
Issues Found:
Confidence Score: 3/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client
participant HttpServer
participant GeminiAgent
participant BAMLExtractor
participant VercelAI as Vercel AI SDK
participant LLM
Note over Client,LLM: Chat with Structured Output Flow
Client->>HttpServer: POST /chat<br/>{message, responseSchema}
HttpServer->>GeminiAgent: execute(message, honoStream, signal, responseSchema)
loop Agent Execution (until no tool calls)
GeminiAgent->>VercelAI: generateContentStream()
VercelAI->>LLM: Stream request
LLM-->>VercelAI: Stream response
VercelAI-->>GeminiAgent: Response chunks
GeminiAgent->>HttpServer: Write SSE chunks
HttpServer-->>Client: Stream agent response
opt Tool calls detected
GeminiAgent->>GeminiAgent: executeToolCall()
end
end
Note over GeminiAgent,BAMLExtractor: Structured Output Extraction
alt responseSchema provided
GeminiAgent->>GeminiAgent: buildExtractionContext(history, 4)
GeminiAgent->>BAMLExtractor: extract(query, context, schema, config)
BAMLExtractor->>BAMLExtractor: jsonSchemaToBAML(schema)
BAMLExtractor->>BAMLExtractor: b.request.Extract()<br/>(render BAML prompt)
BAMLExtractor->>VercelAI: generateTextFromPrompt(prompt)
VercelAI->>LLM: Generate structured data
LLM-->>VercelAI: Response text
VercelAI-->>BAMLExtractor: LLM response
BAMLExtractor->>BAMLExtractor: b.parse.Extract()<br/>(SAP parsing)
BAMLExtractor-->>GeminiAgent: Extracted data
GeminiAgent->>HttpServer: Write SSE (structured-output)
HttpServer-->>Client: Structured output event
end
Note over Client,LLM: Standalone Extract Endpoint
Client->>HttpServer: POST /extract<br/>{query, content, schema}
HttpServer->>BAMLExtractor: extract(query, content, schema, config)
BAMLExtractor->>BAMLExtractor: jsonSchemaToBAML(schema)
BAMLExtractor->>BAMLExtractor: b.request.Extract()
BAMLExtractor->>VercelAI: generateTextFromPrompt(prompt)
VercelAI->>LLM: Generate structured data
LLM-->>VercelAI: Response text
VercelAI-->>BAMLExtractor: LLM response
BAMLExtractor->>BAMLExtractor: b.parse.Extract()
BAMLExtractor-->>HttpServer: Extracted data
HttpServer-->>Client: JSON response
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
14 files reviewed, 1 comment
| case 'object': | ||
| return `map<string, string>${nullSuffix}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: nested object properties are lost - converts to map<string, string> instead of recursively generating BAML classes
| case 'object': | |
| return `map<string, string>${nullSuffix}`; | |
| case 'object': | |
| if (schema.properties && Object.keys(schema.properties).length > 0) { | |
| throw new Error('Nested objects with properties not yet supported. Consider flattening schema or handling at top level.'); | |
| } | |
| return `map<string, string>${nullSuffix}`; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/agent/src/baml/schemaConverter.ts
Line: 47:48
Comment:
**logic:** nested object properties are lost - converts to `map<string, string>` instead of recursively generating BAML classes
```suggestion
case 'object':
if (schema.properties && Object.keys(schema.properties).length > 0) {
throw new Error('Nested objects with properties not yet supported. Consider flattening schema or handling at top level.');
}
return `map<string, string>${nullSuffix}`;
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support added for nested objects
No description provided.