Overview
AgentMark supports JSON Schema$ref references in prompt schemas. Instead of duplicating the same schema definition across multiple prompts, you can extract shared definitions into .json files and reference them with $ref. At build time, AgentMark resolves all references and inlines the content.
This keeps schemas DRY: define a schema once and reuse it across many prompts. When you update a referenced schema, every prompt that points to it picks up the change.
Schema references work in both input_schema (input validation) and object_config.schema (structured output).
Basic usage
Create a JSON schema file, then reference it from your prompt’s frontmatter using$ref.
Schema file
schemas/user.json
Prompt file with $ref
greet-user.prompt.mdx
schemas/user.json and replaces the $ref with the full schema content. The result is identical to having written the schema inline.
Using $ref in output schemas
You can also use $ref in object_config.schema to define the structure of generated objects.
extract-contact.prompt.mdx
Using $ref for nested properties
You don’t need to replace the entire schema with a $ref. You can use $ref for individual properties within a larger schema.
create-order.prompt.mdx
JSON pointer fragments
You can reference a specific definition within a schema file using a JSON Pointer fragment (RFC 6901). This is useful when you have a file containing multiple related definitions.Definitions file
schemas/common.json
Referencing a specific definition
contact-form.prompt.mdx
#/$defs/Address fragment tells AgentMark to navigate into the JSON object at $defs then Address, and inline only that portion. The fragment follows standard JSON Pointer syntax, so any nested path works (for example, #/$defs/contact/email).
Both
$defs and definitions work with AgentMark since the fragment is just a JSON Pointer path into the file.Transitive references
Schema files can themselves contain$ref entries that point to other files. AgentMark follows the entire chain and inlines everything.
Example
schemas/user.json
schemas/address.json
user-profile.prompt.mdx
user.json, then sees the $ref to address.json inside it, resolves that too, and produces a fully inlined schema. Transitive references also work with JSON Pointer fragments. A referenced file can use $ref: ./geo.json#/definitions/Coordinate and it resolves correctly.
AgentMark supports up to 50 levels of transitive references.
Fragment-only references like
$ref: "#/$defs/Address" (no file path) are standard JSON Schema internal references. AgentMark preserves these as-is for runtime validation and doesn’t attempt to resolve them.Security constraints
AgentMark enforces security boundaries on$ref resolution.
- Local files only: AgentMark supports only relative file paths. It doesn’t fetch remote URLs like
https://example.com/schema.json. - Project directory boundary: Resolved paths must stay within the project directory. The content loader rejects path traversal attempts like
../../../etc/passwd. - No absolute paths: AgentMark rejects absolute paths like
/etc/passwd. - AgentMark drops sibling properties: When AgentMark resolves a
$ref, the referenced content replaces the entire object. AgentMark discards any sibling properties next to$ref(likedescription). Place additional properties in the referenced schema file instead.
Error handling
When AgentMark can’t resolve a$ref, it throws an error prefixed Schema $ref error: .
Have questions?
Reach out any time:
- Email the team at hello@agentmark.co for support
- Schedule an Enterprise Demo to learn about AgentMark’s business solutions