Created
September 18, 2025 10:00
-
-
Save axl89/525d9cbb15031f2f0e22aea406b6ac5b to your computer and use it in GitHub Desktop.
Mistral Typescript client bug with complex types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { z } from 'zod'; | |
| import { Mistral } from '@mistralai/mistralai'; | |
| import dotenv from 'dotenv'; | |
| dotenv.config(); | |
| async function testSchemaStep(schema, name) { | |
| try { | |
| const client = new Mistral({ | |
| apiKey: process.env.MISTRAL_API_KEY | |
| }); | |
| const response = await client.chat.parse({ | |
| model: "mistral-large-latest", | |
| messages: [{ role: "user", content: `Create sample data for ${name}` }], | |
| responseFormat: schema, | |
| temperature: 0, | |
| }); | |
| console.log(`β ${name}: WORKS`); | |
| return true; | |
| } catch (error) { | |
| console.log(`β ${name}: FAILS - ${error.message}`); | |
| return false; | |
| } | |
| } | |
| async function findBreakingPoint() { | |
| console.log('π Finding exactly where your schema breaks...\n'); | |
| // Step 1: Basic citation (this works from our tests) | |
| const Citation = z.object({ | |
| pages: z.array(z.number()), | |
| quote: z.string().optional(), | |
| }); | |
| await testSchemaStep(Citation, 'Basic Citation'); | |
| // Step 2: Text with citations | |
| const TextWithCitations = z.object({ | |
| text: z.string(), | |
| citations: z.array(Citation).optional(), | |
| }); | |
| await testSchemaStep(TextWithCitations, 'Text with Citations'); | |
| // Step 3: Rule item | |
| const RuleItem = z.object({ | |
| label: z.string(), | |
| detail: z.string().optional(), | |
| citations: z.array(Citation).optional(), | |
| }); | |
| await testSchemaStep(RuleItem, 'Rule Item'); | |
| // Step 4: Money object | |
| const Money = z.object({ | |
| amount: z.number(), | |
| currency: z.string().default("EUR"), | |
| }); | |
| await testSchemaStep(Money, 'Money'); | |
| // Step 5: Eligibility with arrays | |
| const Eligibility = z.object({ | |
| company_requirements: z.array(RuleItem).optional(), | |
| project_requirements: z.array(RuleItem).optional(), | |
| financial_requirements: z.array(RuleItem).optional(), | |
| }); | |
| await testSchemaStep(Eligibility, 'Eligibility'); | |
| // Step 6: Financing | |
| const Financing = z.object({ | |
| instrument_type: z.enum(["GRANT", "LOAN", "PARTICIPATIVE_LOAN", "MIXED"]), | |
| grant_coverage_pct: z.number().optional(), | |
| grant_amount_cap: Money.optional(), | |
| loan_coverage_pct: z.number().optional(), | |
| min_financing: Money.optional(), | |
| max_financing: Money.optional(), | |
| loan_duration_months: z.number().optional(), | |
| interest_type: z.enum(["FIXED", "VARIABLE", "PROFIT_LINKED"]).optional(), | |
| interest_rate_pct: z.number().optional(), | |
| notes: z.string().optional(), | |
| citations: z.array(Citation).optional(), | |
| }); | |
| await testSchemaStep(Financing, 'Financing'); | |
| // Step 7: Minimal version of your full schema | |
| const MinimalFull = z.object({ | |
| schema_version: z.literal("1.0"), | |
| line_name: z.string(), | |
| overview: TextWithCitations, | |
| instrument_type: z.enum(["GRANT", "LOAN", "PARTICIPATIVE_LOAN", "MIXED"]), | |
| }); | |
| await testSchemaStep(MinimalFull, 'Minimal Full Schema'); | |
| // Step 8: Add eligibility | |
| const WithEligibility = z.object({ | |
| schema_version: z.literal("1.0"), | |
| line_name: z.string(), | |
| overview: TextWithCitations, | |
| instrument_type: z.enum(["GRANT", "LOAN", "PARTICIPATIVE_LOAN", "MIXED"]), | |
| eligibility: Eligibility.optional(), | |
| }); | |
| await testSchemaStep(WithEligibility, 'With Eligibility'); | |
| // Step 9: Add financing (this might be the breaking point) | |
| const WithFinancing = z.object({ | |
| schema_version: z.literal("1.0"), | |
| line_name: z.string(), | |
| overview: TextWithCitations, | |
| instrument_type: z.enum(["GRANT", "LOAN", "PARTICIPATIVE_LOAN", "MIXED"]), | |
| eligibility: Eligibility.optional(), | |
| financing: Financing.optional(), | |
| }); | |
| await testSchemaStep(WithFinancing, 'With Financing'); | |
| // Step 10: Your exact full schema | |
| const FullSchema = z.object({ | |
| schema_version: z.literal("1.0"), | |
| line_name: z.string(), | |
| organizer: z.string().optional(), | |
| jurisdiction: z.string().optional(), | |
| overview: TextWithCitations, | |
| instrument_type: z.enum(["GRANT", "LOAN", "PARTICIPATIVE_LOAN", "MIXED"]), | |
| eligibility: Eligibility.optional(), | |
| financing: Financing.optional(), | |
| notes: z.string().optional(), | |
| }); | |
| await testSchemaStep(FullSchema, 'Full Schema (Exact Copy)'); | |
| console.log('\nπ― This will show us exactly where the complexity breaks!'); | |
| } | |
| findBreakingPoint().catch(console.error); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The bug is:
Package JSON for reference: