Skip to content

Add a separate schema model for LLM structured output#506

Merged
adamnsch merged 4 commits into
neo4j:mainfrom
adamnsch:adamnsch/structured-output-schema
Apr 10, 2026
Merged

Add a separate schema model for LLM structured output#506
adamnsch merged 4 commits into
neo4j:mainfrom
adamnsch:adamnsch/structured-output-schema

Conversation

@adamnsch
Copy link
Copy Markdown
Contributor

@adamnsch adamnsch commented Apr 8, 2026

Description

Summary

Introduces a lean GraphSchemaExtractionOutput model for schema-from-text structured output (response_format) instead of GraphSchema, then converts to GraphSchema via GraphSchema.from_extraction_output so the rest of the pipeline is unchanged.

Details

  • Extracted* types + reused Pattern / ConstraintType; shared Neo4jPropertyTypeName with PropertyType
  • make_strict_json_schema_for_structured_output in neo4j_graphrag.utils.json_schema_structured_output (used by GraphSchema.model_json_schema and the extraction model)
  • validate_extraction_dict_to_graph_schema for shared validation after extraction
  • Docs + CHANGELOG updated

Why

Smaller provider JSON schemas (no root additional_*, fewer defs) and clearer separation between schema extraction LLM structure output format and runtime pipeline config GraphSchema.
It will now be much easier to separate concerns between these two previous roles of GraphSchema.

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update
  • Project configuration change
  • Refactor

Complexity

Note

Please provide an estimated complexity of this PR of either Low, Medium or High

Complexity: Medium

How Has This Been Tested?

  • Unit tests
  • E2E tests
  • Manual tests

Checklist

The following requirements should have been met (depending on the changes in the branch):

  • Documentation has been updated
  • Unit tests have been updated
  • E2E tests have been updated
  • Examples have been updated
  • New files have copyright header
  • CLA (https://neo4j.com/developer/cla/) has been signed
  • CHANGELOG.md updated if appropriate

@adamnsch adamnsch marked this pull request as ready for review April 8, 2026 14:42
@adamnsch adamnsch requested a review from a team as a code owner April 8, 2026 14:42
Copy link
Copy Markdown
Contributor

@NathalieCharbel NathalieCharbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
I like this new separation of the extracted model from GraphSchema.

Comment thread src/neo4j_graphrag/experimental/components/schema.py Outdated
@adamnsch adamnsch force-pushed the adamnsch/structured-output-schema branch from 007830d to f9f95ca Compare April 10, 2026 07:15
@adamnsch adamnsch merged commit a268aed into neo4j:main Apr 10, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants