Checked other resources
Example Code
// Define the output format selection schema
const OutputFormatSelectionSchema = z.object({
query: z
.string()
.describe('The search query'),
});
const model = ChatGoogle({
model: 'gemini-2.5-flash-lite',
temperature: 0,
});
const structuredLlm = withStructuredOutput(model, OutputFormatSelectionSchema);
const result = await structuredLlm.invoke("Generate a search query")
Error Message and Stack Trace (if applicable)
No response
Description
With structuredOutput is defaulting to extract tool because of missing logic for Gemini native structured out.
This usually results in much worse results for JSON generation.
To get native json generation we would need to pass responseMimeType and responseSchema to the API request.
https://ai.google.dev/gemini-api/docs/structured-output#javascript
System Info
Node: v23.11.0
Mac OS X
langchain@0.3.30 | MIT | deps: 11 | versions: 325
Typescript bindings for langchain
https://github.com/langchain-ai/langchainjs/tree/main/langchain/
keywords: llm, ai, gpt3, chain, prompt, prompt engineering, chatgpt, machine learning, ml, openai, embeddings, vectorstores
dist
.tarball: https://registry.npmjs.org/langchain/-/langchain-0.3.30.tgz
.shasum: 9fc0467007009dc5e799d1f8fb9dd1137654e387
.integrity: sha512-UyVsfwHDpHbrnWrjWuhJHqi8Non+Zcsf2kdpDTqyJF8NXrHBOpjdHT5LvPuW9fnE7miDTWf5mLcrWAGZgcrznQ==
.unpackedSize: 2.9 MB
dependencies:
@langchain/openai: >=0.1.0 <0.7.0 openapi-types: ^12.1.3
@langchain/textsplitters: >=0.0.0 <0.2.0 p-retry: 4
js-tiktoken: ^1.0.12 uuid: ^10.0.0
js-yaml: ^4.1.0 yaml: ^2.2.1
jsonpointer: ^5.0.1 zod: ^3.25.32
langsmith: ^0.3.33
published a week ago by davidduong david@duong.cz
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
No response
Description
With structuredOutput is defaulting to extract tool because of missing logic for Gemini native structured out.
This usually results in much worse results for JSON generation.
To get native json generation we would need to pass
responseMimeTypeandresponseSchemato the API request.https://ai.google.dev/gemini-api/docs/structured-output#javascript
System Info
Node: v23.11.0
Mac OS X
langchain@0.3.30 | MIT | deps: 11 | versions: 325
Typescript bindings for langchain
https://github.com/langchain-ai/langchainjs/tree/main/langchain/
keywords: llm, ai, gpt3, chain, prompt, prompt engineering, chatgpt, machine learning, ml, openai, embeddings, vectorstores
dist
.tarball: https://registry.npmjs.org/langchain/-/langchain-0.3.30.tgz
.shasum: 9fc0467007009dc5e799d1f8fb9dd1137654e387
.integrity: sha512-UyVsfwHDpHbrnWrjWuhJHqi8Non+Zcsf2kdpDTqyJF8NXrHBOpjdHT5LvPuW9fnE7miDTWf5mLcrWAGZgcrznQ==
.unpackedSize: 2.9 MB
dependencies:
@langchain/openai: >=0.1.0 <0.7.0 openapi-types: ^12.1.3
@langchain/textsplitters: >=0.0.0 <0.2.0 p-retry: 4
js-tiktoken: ^1.0.12 uuid: ^10.0.0
js-yaml: ^4.1.0 yaml: ^2.2.1
jsonpointer: ^5.0.1 zod: ^3.25.32
langsmith: ^0.3.33
published a week ago by davidduong david@duong.cz