Extracts JSON schema from Python functions using docstrings and Pydantic for LLM calls.
# Source: https://github.com/howl-anderson/agentsilex | License: MIT | Copyright 2025 Xiaoquan Kong
# Provided via justclaw.it.com; keep this notice with the code.
"""
Simplified function schema extraction for LLM function calling.
Uses docstring_parser and pydantic for clean, maintainable implementation.
"""
from __future__ import annotations
import inspect
from typing import Any, Optional, Union, get_args, get_origin, get_type_hints
from docstring_parser import parse
from pydantic import BaseModel, Field, create_model
def extract_function_schema(
func: Any,
name_override: str | None = None,
description_override: str | None = None,
) -> tuple[str, str | None, dict[str, Any]]:
"""
Given a Python function, extracts schema information for LLM function calling.
T
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key