Skip to main content

Text to Weaver

Text to Weaver is a powerful feature in ObjectWeaver that allows you to generate complex JSON Schema definitions from simple natural language prompts. Instead of manually crafting intricate jsonSchema.Definition objects, you can describe what you want in plain English, and ObjectWeaver will build the schema for you.

Objectives

The objective of the Text to Weaver endpoint is threefold:

  • First is the ease of experimentation: It helps you get most of the way to an initial schema design based on the information you're working with.
  • Second, and more interestingly: It provides a way for an agent or AI system to dynamically create definitions for a given endpoint, which when paired with code generation can lead to some fun shenanigans. This kind of functionality is currently experimental at ObjectWeaver; let us know if you've got something fun working!
  • Thirdly, structural guidance: The recursive schema format, which allows for deeply nested structures, provides a helpful blueprint for how to create complex schemas and definitions.

Endpoint

  • URL: /api/textToWeaver
  • Method: POST
  • Environment: Only available in development mode.

Request Format

The request should be a JSON object with a single prompt field.

{
"prompt": "Create a user profile with name, email, and an address containing street and city"
}

Response Format

The response returns a definition object that is compatible with the /api/objectGen endpoint.

{
"definition": {
"type": "object",
"instruction": "Generate a definition for a user profile with name, email, bio, and address including street, city, and postal code",
"properties": {
"address": {
"type": "object",
"instruction": "Generate address details",
"properties": {
"city": {
"type": "string",
"instruction": "Generate city details",
"properties": {},
"HashMap": null,
"epistemic": {}
},
"postalCode": {
"type": "string",
"instruction": "Generate details for postal code",
"properties": {},
"HashMap": null,
"epistemic": {}
},
"street": {
"type": "string",
"instruction": "Generate street details",
"properties": {},
"HashMap": null,
"epistemic": {}
}
},
"HashMap": null,
"epistemic": {}
},
"bio": {
"type": "string",
"instruction": "Write a short biography.",
"properties": {},
"HashMap": null,
"epistemic": {}
},
"email": {
"type": "string",
"instruction": "Generate email address",
"properties": {},
"HashMap": null,
"epistemic": {}
},
"name": {
"type": "string",
"instruction": "Generate name details",
"properties": {},
"HashMap": null,
"epistemic": {}
}
},
"HashMap": null,
"epistemic": {}
}
}

How It Works

Text to Weaver uses a specialized "meta-schema" to guide an LLM through the process of schema creation. This process involves several steps:

  1. Structural Analysis: The LLM identifies which fields are simple (strings, numbers) and which are complex (objects, arrays).
  2. Decomposition: The request is broken down into root-level fields and nested structures.
  3. Recursive Generation: The LLM generates definitions for each field, including nested fields for complex types, using a recursive structure.
  4. Schema Flattening: The system is designed to avoid redundant nesting. For example, if you ask to "Create a User", it will generate a schema where the root properties are name, email, etc., rather than a single user property containing those fields.
  5. Post-Processing: ObjectWeaver performs several post-processing steps to ensure the generated schema is robust:
    • Name Recovery: If the LLM uses generic names, ObjectWeaver attempts to recover the intended names from the initial analysis.
    • Hierarchy Reconstruction: It uses hints from the LLM's analysis to correctly nest properties that might have been flattened.
    • Type Sanitization: Ensures all field types are valid JSON Schema types.

Usage Workflow

  1. Generate Schema: Call /api/textToWeaver with your description.
  2. Review/Modify: (Optional) Review the generated schema and make any necessary adjustments.
  3. Generate Data: Use the generated schema as the definition in a call to /api/objectGen to generate the actual data.

This workflow significantly reduces the time and effort required to set up complex data generation tasks, especially when dealing with deeply nested structures.