Core spec: allow ai_context and custom_extensions on the document root - #323
Open
eisber wants to merge 1 commit into
Open
Core spec: allow ai_context and custom_extensions on the document root#323eisber wants to merge 1 commit into
eisber wants to merge 1 commit into
Conversation
The root object is the only node in the spec with no ai_context and no custom_extensions: both appear on SemanticModel, Dataset, Field, Metric and Relationship, but the document itself is closed (additionalProperties: false) with only version and semantic_model. A document holds a LIST of semantic models, so guidance that governs all of them has nowhere to live. A producer emitting one model per data source must copy shared instructions into every model so no model can be read without them, and a consumer cannot tell those copies apart from genuinely model-specific instruction. Document-wide context is already an established shape in Ossie: an ontology document carries ai_context on its root and $refs this specification's AIContext definition. Core documents were the only root without it, so this follows the existing precedent rather than introducing a new concept, and a test pins the two roots to the same definition. Both keys are optional and the root stays closed, so existing documents validate unchanged. Refs: apache#322
There was a problem hiding this comment.
Pull request overview
Adds support for document-scoped guidance and vendor metadata by allowing ai_context and custom_extensions on the core spec document root, aligning the core document root with patterns already used elsewhere (and with the ontology root).
Changes:
- Extend
core-spec/osi-schema.jsondocument root with optionalai_contextandcustom_extensions(root remains closed). - Update the Python reference model and tests to parse/serialize
ai_context/custom_extensionsat the document level. - Update spec/docs to document the new document-level fields and their precedence semantics.
Show a summary per file
| File | Description |
|---|---|
| python/tests/test_models.py | Adds regression tests asserting schema/root parity and round-trip serialization for document-level ai_context and custom_extensions. |
| python/src/ossie/models.py | Adds ai_context and custom_extensions to the OSIDocument Pydantic model. |
| docs/index.md | Updates docs text to include document-level AI context. |
| core-spec/spec.yaml | Documents root-level ai_context / custom_extensions in the YAML spec summary. |
| core-spec/spec.md | Adds a new “Document” section with a worked example and precedence semantics. |
| core-spec/osi-schema.json | Adds the new optional root properties with descriptions; keeps additionalProperties: false. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
Comment on lines
211
to
+216
| version: str = "0.2.0.dev0" | ||
| dialects: Optional[list[OSIDialect]] = None | ||
| vendors: Optional[list[OSIVendor]] = None | ||
| ai_context: Optional[OSIAIContext] = None | ||
| semantic_model: list[OSISemanticModel] | ||
| custom_extensions: Optional[list[OSICustomExtension]] = None |
Comment on lines
+61
to
+73
| # Optional: Document-wide context for AI tools. | ||
| # Applies to every semantic model in this document. Model-level ai_context adds to | ||
| # it and takes precedence where the two conflict. | ||
| # Use this for guidance that governs the document as a whole — a model read in | ||
| # isolation would otherwise have to repeat it. | ||
| # Can be a simple string or a structured object with instructions, | ||
| # synonyms, examples, or vendor-specific keys. | ||
| ai_context: | ||
| instructions: string | ||
| synonyms: | ||
| - string | ||
| examples: | ||
| - string |
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.
Summary
The document root is the only node in the core spec with no
ai_contextand nocustom_extensions. Both keys appear onSemanticModel,Dataset,Field,MetricandRelationship; the root is closed (additionalProperties: false) with onlyversionandsemantic_model.Since
semantic_modelis a list, guidance that governs every model in a document has nowhere to live. A producer emitting one model per data source must copy shared instructions into each model, and a consumer cannot tell those copies apart from genuinely model-specific instruction. See #322 for the full motivation.This PR adds two optional keys to the document root:
ai_context$ref: #/$defs/AIContextcustom_extensions#/$defs/CustomExtensionSemantics: document-level context applies to every semantic model in the document; model-level
ai_contextadds to it and takes precedence where the two conflict.Precedent
This is not a new concept for the project. An ontology document already carries
ai_contexton its root, and$refs this spec's definition:The core spec already defines document-wide AI context — the core document root was simply the only root that never consumed it. A test pins both roots to the same
AIContextdefinition so they cannot drift.Not a breaking change
$defs— both keys reuse existing definitions.requiredis unchanged; both keys are optional.additionalProperties: falseis unchanged, so the root stays closed. Unknown root keys, a wrong-typedai_context, and an extension missingdataare all still rejected.examples/tpcds_semantic_model.yamlvalidates unchanged, and absent keys do not serialize.Interaction with other open work
dialects,vendors) that were never in the schema. This PR is compatible in substance and goes the other way round: it adds to the schema first and leaves the root closed. Under Keep converter outputs aligned with root schema #306'sextra="forbid", declared fields still validate.spec.yamlto showai_contextas a structured object (drift core-spec/spec.yaml declaresai_context: stringbut the JSON schema + canonical example use a structured object #141). The root entry added here uses docs: align spec yaml ai_context shape #221's shape, so it does not re-introduce the drift.ai_contextshould exist at all. That is a broader question; this PR only makes the existing construct available at the one level where it is missing.Related Issues
Refs #322
Checklist
Specification
core-spec/and follow the existing structureOntology
ontology/are consistent with spec changes —ontology/is untouched; it already had rootai_contextand this aligns core with itConverters
converters/is updated to reflect spec or ontology changes — not applicable, both keys are optional and no converter emits themValidation
validation/are updated if the spec changed —validate.pyis schema-driven and needed no change; verified positive, negative and back-compat cases against itDocumentation
docs/is updated to reflect any user-facing changesspec.mdwith a worked exampleCONTRIBUTING.mdis updated if the contribution process changed — not applicableExamples
examples/are added or updated for any new spec constructs — no example changes; the worked example lives inspec.md, andtpcds_semantic_model.yamlis intentionally left unchanged to demonstrate back-compatTests
pytest/ CI green) — 9 -> 14 passingAIContextdefinitionCompliance