Skip to content
Agentmart
Submit a tool

dk-lm-studio-pydantic-ai

Use LM Studio as a local LLM backend with Pydantic AI for structured output extraction.

Skill by opencode

IndexedMIT
Write a review

Chalk Labs

Need help deploying dk-lm-studio-pydantic-ai?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/dushyantkhosla-dk-lm-studio-pydantic-ai

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Use LM Studio as a local LLM backend with Pydantic AI for structured output extraction. Provides server setup, agent configuration, and extraction patterns using OpenAI-compatible API with local models. Use when user wants local inference, offline AI, or self-hosted LLMs.

Use cases: backend, ml, agent-building

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md and code. Checked Nov 1, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Python package

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/dk-lm-studio-pydantic-ai

What's inside

Skill name
dk-lm-studio-pydantic-ai
Description
Use LM Studio as a local LLM backend with Pydantic AI for structured output extraction. Provides server setup, agent configuration, and extraction patterns using OpenAI-compatible API with local models. Use when user wants local inference, offline AI, or self-hosted LLMs.
License
MIT
Compatibility
Requires Python 3.10+, LM Studio, pydantic-ai. The `lmstudio` Python package is optional (CLI-based helpers used by default).
Metadata
author: opencode · version: 1.0.0 · opencode/autoinvoke: false
Instructions
390 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts

Files (2)

  • SKILL.md
  • lmstudio_utils.py · references/

SKILL.md (first lines)

# LM Studio with Pydantic AI

Use LM Studio as a local inference backend with Pydantic AI to extract structured data from text using self-hosted LLMs.

## When to Use This Skill

Invoke this skill when:

- User wants to use a local LLM (LM Studio) with Pydantic AI
- User mentions LM Studio, local inference, offline AI, or self-hosted LLMs
- User asks to extract structured data from text (keywords, entities, sentiment)
- Building document processing pipelines
- Need structured output without API calls to OpenAI/Anthropic

Do **not** use this skill for:

- Cloud-based LLM providers (OpenAI, Anthropic, Google)
- General Pydantic AI agent patterns (use `building-pydantic-ai-agents` instead)
- Non-Pydantic AI frameworks

## Prerequisites

```bash
uv add "pydantic-ai-slim[openai]" python-dotenv
```

The `lmstudio` Python package is **optional** — by default, CLI-based helpers are used. If you prefer the Python SDK approach, add it with `uv add lmstudio`.

Ensure LM Studio is installed with a downloaded model.

## Quick-Start Patterns

### Ensure Model is Loaded

Always call this before creating any Pydantic AI agent. The helper functions are in `references/lmstudio_utils.py`:

```python
# lm_server.py (CLI-based, no extra package needed)
import sys
sys.path.insert(0, "path/to/references")
from lmstudio_utils import ensure_model_loaded

def ensure_model_loaded(model_name: str) -> str:
    """Ensure LM Studio server is running and model is loaded. Returns model identifier."""
    from lmstudio_utils import ensure_server_running, load_model
    ensure_server_running()
    return load_model(model_name)
```

### Create a Structured Output Agent

```python
import os
from pydantic import BaseModel
from typing import List

from dotenv import find_dotenv, load_dotenv
load_dotenv(find_dotenv())

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider
from pydantic_ai.settings import ModelSettings
from pydantic_ai.exceptions import UnexpectedModelBehavior

from lm_server import ensure_model_loaded

INFERENCE_MODEL = os.getenv("LOCAL_MODEL_INFERENCE")  # Required - must be set in .env
LMSTUDIO_BASE_URL = os.getenv("LMSTUDIO_BASE_URL", "http://localhost:1234/v1")


# Define output schema (customize for your use case)
class PersonInfo(BaseModel):
    name: str
    email: str
    skills: List[str]


# Create agent
def extract_person_info(text: str) -> PersonInfo:
    ensure_model_loaded(INFERENCE_MODEL)

    agent = Agent(
        model=OpenAIChatModel(
            INFERENCE_MODEL,
            provider=OpenAIProvider(
                base_url=LMSTUDIO_BASE_URL,
                api_key="x",
            ),
        ),
        model_settings=ModelSettings(
            thinking=False,
            extra_body={"chat_template_kwargs": {"enable_thinking": False}},
        ),
        retries=5,
        output_type=PersonInfo,
        instructions="Extract person information from the text. Return only valid JSON.",
    )

    try:
        return agent.run_sync(user_prompt=text).output
    except UnexpectedModelBehavior as exc:
        raise RuntimeError(f"Extraction failed: {exc}")
```

### Agent Factory Pattern

For reusable agents:

```python
from typing import Type
from pydantic import BaseModel


def create_extractor(output_type: Type[BaseModel], instructions: str):
    """Factory for creating extraction agents."""
    return Agent(
        model=OpenAIChatModel(
            INFERENCE_MODEL,

From dushyantkhosla/agent-skills, MIT.

More from dushyantkhosla/agent-skills

Compare and alternatives

    Featured in

    Signals

    Stars
    0
    Forks
    1
    Open issues
    0
    Last commit (this folder)
    Oct 7, 2026 (1 month ago)

    From GitHub (fetched Oct 24, 2026).

    Details

    Version
    1.0.0
    License
    MIT
    First seen
    Oct 24, 2026
    Last checked
    Oct 24, 2026

    More from opencode

    Done for you

    Rather not set it up yourself?

    Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

    See how we build AI agents →Read the case studies

    Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

    launches shipped
    50+
    launches shipped
    media placements
    500+
    media placements
    founders on every account
    2
    founders on every account

    Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

    Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

    Get dk-lm-studio-pydantic-ai running in your business

    Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

    Goes to the Chalk Labs founders, not the newsletter. Privacy

    Need help deploying dk-lm-studio-pydantic-ai?

    CallGet help
    Cite this page

    dk-lm-studio-pydantic-ai skill. Agent Mart. https://agentmart.dev/skills/dushyantkhosla-dk-lm-studio-pydantic-ai (last updated 2026-10-24)