feat(go): add DefineSchemasFor and drop core.DefineSchemaFor - #5885
Open
apascal07 wants to merge 3 commits into
Open
feat(go): add DefineSchemasFor and drop core.DefineSchemaFor#5885apascal07 wants to merge 3 commits into
DefineSchemasFor and drop core.DefineSchemaFor#5885apascal07 wants to merge 3 commits into
Conversation
…SchemasFor DefineSchemaFor took one type parameter per call, so registering the handful of schemas a .prompt-using app needs meant one statement each. DefineSchemasFor takes values instead of a type parameter and registers any number of them in a single call. Taking values also lets it reject inputs the type-parameter form could not: a map now panics pointing at DefineSchema(name, schema) instead of being registered as a schema named "", and nil or an unnamed type panics rather than dereferencing a nil reflect.Type. core is plugin and internal plumbing, so the old function is removed outright rather than kept as a shim. genkit.DefineSchemaFor, the app-facing touchpoint, is unaffected and stays.
Registers any number of Go-type schemas in one call:
genkit.DefineSchemasFor(g, JokeRequest{}, Joke{}, Recipe{})
genkit.DefineSchemaFor stays as the single-type form for when naming the
type reads better than constructing a value of it, and now delegates to
core.DefineSchemasFor so both paths register identical schemas.
basic-prompts collapses five DefineSchemaFor statements into one call.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces DefineSchemasFor, a new function that allows registering multiple JSON schemas derived from Go types in a single call. It refactors existing code, documentation, and samples to use this new variadic function instead of multiple sequential calls to DefineSchemaFor. Additionally, comprehensive unit tests have been added to verify its behavior, including panic conditions for invalid inputs like maps, unnamed types, and nil values. There are no review comments, so I have no additional feedback to provide.
apascal07
marked this pull request as ready for review
August 1, 2026 17:34
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports
DefineSchemasForfrom the Go V2 branch (#5814). Registering the schemas a.prompt-using app needs took oneDefineSchemaFor[T]statement per type, since a type parameter cannot be variadic.DefineSchemasFortakes values instead, so one call covers as many types as the app has.Before: one statement per type.
After: one call. The registry name and the schema are still inferred from each value's Go type, so
.promptfrontmatter referencingschema: Jokeresolves exactly as before.core.DefineSchemaForis deleted,genkit.DefineSchemaForstayscoreis plugin and internal plumbing, so its copy goes rather than becoming a shim, followingai.DefineFormatin #5861.genkit.DefineSchemaForis the app-facing touchpoint and is not deprecated: for a single type, naming it still reads better than constructing a value of it. It now delegates tocore.DefineSchemasFor, so the two forms cannot drift.Taking a value rather than a type parameter also lets registration reject input that never produced a usable schema.
DefineSchemaFor[map[string]any]andDefineSchemaFor[struct{ ... }]registered under the empty name, andDefineSchemaFor[SomeInterface]dereferenced a nilreflect.Type. All three now panic with a message pointing atDefineSchema(name, schema), which is the call that can name a schema explicitly. That is the only behavior change to the kept function.Scope
DefineSchema(g, name, schema)is untouched. A raw JSON schema map has no Go type to take a name from, which is why passing one toDefineSchemasForpanics instead of guessing..promptchange. Schemas land in the same registry under the same names; only the number of statements it takes to get them there changes.Testing
Go 1.26.3, full
go test ./...ingo/: 40 packages pass, no failures.go/samplesbuilds and vets clean.core_test.gocovers multi-value registration, pointer values, and each of the three panic paths.genkit_test.gokeepsDefineSchemaForcoverage for both value and pointer type arguments, pinning it to the same schemasDefineSchemasForproduces.