You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add allOf, anyOf, oneOf, not to illuminate/json-schema
#59643
I was creating an agent with structured output with laravel/ai and I noticed I can't use allOf, anyOf, oneOf, not in my json schema.
I had to write my own custom implementation that extends the regular classes.
Here is an example why and how I want to use it.
The example below ensures there is one string inside result.reasons when result.approved = false. (See the ->min(1))
When result.approved = true the other values are omitted.
This is very helpful instead of having no minimum on result.reasons, because without anyOf, AI could return result.approved = false and result.reasons = []
/** * Get the agent's structured output schema definition. */publicfunctionschema(JsonSchema$unused): array
{
$schema = newJsonSchemaTypeFactory;
return [
'result' => $schema->object()->required()->anyOf([
$schema->object([
'approved' => $schema->boolean()->description('Whether the message was approved or denied.')->enum([false])->required(),
'reasons' => $schema->array()
->min(1)
->items($schema->string()->description('The reason why the message was denied.')->enum([
'contains_name',
'contains_age',
'contains_birthdate',
'contains_birthplace',
'contains_address',
'contains_phone_number',
'contains_email_address',
'contains_relation_name',
'contains_location',
'contains_employer_name',
'contains_school_name'
])->required())
->required(),
'explanation' => $schema->string()->description('The explanation for why the message was denied.')->required(),
]),
$schema->object([
'approved' => $schema->boolean()->enum([true])->required(),
]),
]),
];
}
As I said, I have already 'implemented' it myself by overwriting methods and classes where necessary and this works.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I was creating an agent with structured output with laravel/ai and I noticed I can't use
allOf,anyOf,oneOf,notin my json schema.I had to write my own custom implementation that extends the regular classes.
Here is an example why and how I want to use it.
The example below ensures there is one string inside
result.reasonswhenresult.approved = false. (See the->min(1))When
result.approved = truethe other values are omitted.This is very helpful instead of having no minimum on
result.reasons, because withoutanyOf, AI could returnresult.approved = falseandresult.reasons = []As I said, I have already 'implemented' it myself by overwriting methods and classes where necessary and this works.
All reactions