> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eigenai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Function Schema

> Understand the function schema format used in EigenData-CLI for defining tool capabilities.

A **function schema** is a structured JSON specification that defines a callable function or tool available in your system. EigenData-CLI uses function schemas to understand what tools are available and how to invoke them when generating conversational data.

## Providing Function Schema

You can provide function schemas to EigenData-CLI in two ways:

### Option 1: MCP Server

If you have a Model Context Protocol (MCP) server, EigenData-CLI can automatically discover available tools:

1. Provide your MCP server URL during setup or via `/configure`
2. The system automatically discovers available tools from the MCP server
3. Function schemas are generated from the tool definitions

```
eigendata> /configure mcp_server_url http://localhost:8080
```

This approach is ideal when your tools are already defined in an MCP-compatible server.

### Option 2: Local Schema File

Provide a local file containing your function definitions:

```
eigendata> /configure schema_file ./my_functions.json
```

Supported file formats:

| Format | Extension       | Description                          |
| ------ | --------------- | ------------------------------------ |
| JSON   | `.json`         | Array of function objects            |
| JSONL  | `.jsonl`        | One function definition per line     |
| YAML   | `.yaml`, `.yml` | YAML-serialized function definitions |

## Schema Format

Function schemas follow the OpenAI-style JSON Schema format with four basic fields:

```json theme={null}
{
  "name": "CreateReminder",
  "description": "Creates a reminder for the user at a specified time.",
  "parameters": {
    "type": "object",
    "properties": {
      "user_id": {
        "type": "string",
        "description": "The ID of the user creating the reminder."
      },
      "title": {
        "type": "string",
        "description": "The reminder title, e.g., 'Call mom'."
      },
      "remind_at": {
        "type": "string",
        "description": "ISO 8601 datetime for when to trigger the reminder."
      },
      "priority": {
        "type": "string",
        "enum": ["low", "medium", "high"],
        "description": "Priority level of the reminder."
      }
    },
    "required": ["user_id", "title", "remind_at"],
    "additionalProperties": false,
    "examples": [
      {
        "user_id": "user_12345",
        "title": "Team meeting",
        "remind_at": "2024-03-15T09:00:00Z",
        "priority": "high"
      }
    ]
  },
  "returns": {
    "type": "object",
    "description": "The created reminder object.",
    "properties": {
      "reminder_id": {
        "type": "string",
        "description": "Unique identifier for the created reminder."
      },
      "status": {
        "type": "string",
        "description": "Creation status, either 'created' or 'failed'."
      }
    }
  }
}
```

## Schema Fields

| Field         | Type   | Description                                                    |
| ------------- | ------ | -------------------------------------------------------------- |
| `name`        | string | Function identifier (e.g., "create\_reminder", "delete\_task") |
| `description` | string | Human-readable explanation of what the function does           |
| `parameters`  | object | JSON Schema object defining input parameters                   |
| `returns`     | object | JSON Schema object describing the function's return value      |

## Schema File Examples

### Format 1: Standard Array (JSON)

The most common format—an array of function objects:

```json theme={null}
[
  {
    "name": "CreateReminder",
    "description": "Creates a reminder for the user.",
    "parameters": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string",
          "description": "The reminder title."
        },
        "remind_at": {
          "type": "string",
          "description": "ISO 8601 datetime for the reminder."
        }
      },
      "required": ["title", "remind_at"]
    },
    "returns": {
      "type": "object",
      "description": "The created reminder.",
      "properties": {
        "reminder_id": {
          "type": "string",
          "description": "Unique identifier for the reminder."
        }
      }
    }
  },
  {
    "name": "DeleteReminder",
    "description": "Deletes an existing reminder.",
    "parameters": {
      "type": "object",
      "properties": {
        "reminder_id": {
          "type": "string",
          "description": "The ID of the reminder to delete."
        }
      },
      "required": ["reminder_id"]
    },
    "returns": {
      "type": "object",
      "description": "Deletion result.",
      "properties": {
        "success": {
          "type": "boolean",
          "description": "Whether the deletion was successful."
        }
      }
    }
  }
]
```

### Format 2: YAML with `functions` Wrapper

YAML format with an explicit `functions` key:

```yaml theme={null}
functions:
  - name: CreateReminder
    description: Creates a reminder for the user.
    parameters:
      type: object
      properties:
        title:
          type: string
          description: The reminder title.
        remind_at:
          type: string
          description: ISO 8601 datetime for the reminder.
      required:
        - title
        - remind_at
    returns:
      type: object
      description: The created reminder.
      properties:
        reminder_id:
          type: string
          description: Unique identifier for the reminder.

  - name: DeleteReminder
    description: Deletes an existing reminder.
    parameters:
      type: object
      properties:
        reminder_id:
          type: string
          description: The ID of the reminder to delete.
      required:
        - reminder_id
    returns:
      type: object
      description: Deletion result.
      properties:
        success:
          type: boolean
          description: Whether the deletion was successful.
```

### Format 3: Extended Format with `tool` and `input_schema`

This format uses `tool` as the function identifier and `input_schema` as an object defining parameters with inline metadata:

```json theme={null}
[
  {
    "tool": "CreateReminder",
    "description": "Create a new reminder with a due date/time.",
    "input_schema": {
      "name": {
        "type": "string",
        "required": true,
        "description": "Short title for the reminder.",
        "example": "Replace printer ink cartridge"
      },
      "due": {
        "type": "string(date-time)",
        "required": true,
        "description": "When the reminder is due, in ISO 8601 format.",
        "example": "2026-02-01T09:00:00"
      },
      "hint": {
        "type": "string",
        "required": false,
        "description": "Optional notes or instructions.",
        "example": "Check ink levels first."
      }
    },
    "output_schema": {
      "reminderId": "string",
      "name": "string",
      "due": "string(date-time)",
      "status": "string(enum: pending|completed)",
      "error": "object{code:string,message:string}"
    }
  },
  {
    "tool": "DeleteReminder",
    "description": "Delete a reminder by id.",
    "input_schema": {
      "reminderId": {
        "type": "string",
        "required": true,
        "description": "Identifier of the reminder to delete.",
        "example": "rem_12345"
      }
    },
    "output_schema": {
      "deleted": "boolean",
      "reminderId": "string",
      "error": "object{code:string,message:string}"
    }
  }
]
```

| Field           | Description                                                                      |
| --------------- | -------------------------------------------------------------------------------- |
| `tool`          | Function identifier (replaces `name`)                                            |
| `input_schema`  | Object defining parameters with `type`, `required`, `description`, and `example` |
| `output_schema` | Flattened object with field names as keys and type signatures as values          |

## Best Practices

1. **Write clear descriptions** - Each function and parameter should have a description that explains its purpose and expected values.

2. **Use specific types** - Use the most specific JSON Schema type for each parameter (`string`, `integer`, `number`, `boolean`, `array`, `object`).

3. **Mark required fields** - Always specify which parameters are required to help generate valid function calls.

4. **Include examples in descriptions** - Add example values in parameter descriptions (e.g., "Email address such as '[user@example.com](mailto:user@example.com)'").

5. **Define return values** - Always include a `returns` field to document what the function returns. This helps generate realistic tool responses in conversational data.

6. **Use `parameters.examples`** - Provide example parameter objects to demonstrate valid inputs. This improves the quality of generated function calls.
