baml-integration
Generic BAML patterns for type-safe LLM prompting. Covers schema design, DTO generation, client wrappers, and cross-language codegen. Framework-agnostic.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o baml-integration.zip https://jpskill.com/download/18023.zip && unzip -o baml-integration.zip && rm baml-integration.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/18023.zip -OutFile "$d\baml-integration.zip"; Expand-Archive "$d\baml-integration.zip" -DestinationPath $d -Force; ri "$d\baml-integration.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
baml-integration.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
baml-integrationフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
BAML 統合スキル
あらゆるプロジェクトで BAML (Boundary ML) を扱うための汎用的なパターンです。BAML は、Python および TypeScript 用の自動コード生成による、型安全な LLM プロンプトを提供します。
設計原則
このスキルはフレームワークに依存しません。あらゆるコードベースで動作する汎用的な BAML パターンを提供します。
- CodeGraph-DE、Book-Vetting、または特定のプロジェクトに特化していません
- すべての BAML プロジェクトに適用可能な共通パターンを網羅しています
- 特定のドメイン型は、プロジェクト固有のスキルに含める必要があります
変数
| 変数 | デフォルト | 説明 |
|---|---|---|
| BAML_SRC | baml_src | BAML ファイルを含むディレクトリ |
| AUTO_GENERATE | true | 変更時に baml-cli generate を自動実行します |
| STRICT_TYPES | true | 厳密な型の一致を強制します |
手順
必須 - 以下のワークフローの手順を順番に実行してください。
- プロジェクトにおける BAML の役割を理解する
- 既存の BAML スキーマと型を確認する
- LLM を扱う際は、型安全なパターンに従う
- 生成されたコードを同期させておく
危険信号 - 停止して再検討
以下のようなことをしようとしている場合:
- BAML 型なしで LLM プロンプトを定義する
- BAML を使用せずに LLM 出力を手動で解析する
- スキーマ変更後に
baml-cli generateの実行をスキップする - 生成されたクライアントの型エラーを無視する
停止 -> BAML 型を定義 -> クライアントを生成 -> その後続行
ワークフロー
1. プロジェクトの BAML 設定を理解する
BAML の設定を確認します。
# BAML ソースディレクトリを検索
find . -name "*.baml" -type f | head -5
# BAML クライアントを確認
ls -la baml_client/ || ls -la baml_src/baml_client/
# ジェネレーター設定を確認
cat baml_src/generators.baml 2>/dev/null
2. 既存の型を確認する
新しい型を追加する前に、既存のものを確認します。
// baml_src/types/ の共通パターン
// Enum
enum TaskStatus {
PENDING
IN_PROGRESS
COMPLETED
FAILED
}
// クラス (DTO)
class UserRequest {
query string
context string?
preferences map<string, string>?
}
class UserResponse {
answer string
confidence float
sources string[]
}
3. 新しい型を定義する
LLM を利用した機能を追加する場合:
// 1. 入力型を定義
class MyInput {
field1 string @description("明確な説明")
field2 int @description("この数値が表すもの")
}
// 2. 出力型を定義
class MyOutput {
result string
metadata MyMetadata?
}
class MyMetadata {
confidence float
reasoning string
}
// 3. 関数を定義
function MyFunction(input: MyInput) -> MyOutput {
client GPT4
prompt #"
与えられた情報: {{ input.field1 }}
カウント: {{ input.field2 }}
分析を提供してください。
{{ ctx.output_format }}
"#
}
4. クライアントを生成する
スキーマ変更後:
# Python および TypeScript クライアントを生成
baml-cli generate
# または特定の構成で
baml-cli generate --config baml_src/generators.baml
5. 生成されたクライアントを使用する
# Python の使用例
from baml_client import b
async def process_request(input_data: dict):
result = await b.MyFunction(
input=MyInput(
field1=input_data["query"],
field2=input_data["count"]
)
)
return result.result
// TypeScript の使用例
import { b } from './baml_client';
async function processRequest(inputData: Record<string, unknown>) {
const result = await b.MyFunction({
field1: inputData.query as string,
field2: inputData.count as number
});
return result.result;
}
クックブック
スキーマ同期
- IF: BAML 型を追加または変更する場合
- THEN:
./cookbook/schema-sync.mdを読んで実行してください
DTO 生成
- IF: データ転送オブジェクトを作成する場合
- THEN:
./cookbook/dto-generation.mdを読んで実行してください
クライアントラッパーパターン
- IF: サービス用に BAML クライアントをラップする場合
- THEN:
./cookbook/client-wrapper.mdを読んで実行してください
クイックリファレンス
BAML 型の構文
| 型 | 構文 | 例 |
|---|---|---|
| String | string |
name string |
| Int | int |
count int |
| Float | float |
score float |
| Boolean | bool |
active bool |
| Optional | type? |
nickname string? |
| Array | type[] |
tags string[] |
| Map | map<K, V> |
metadata map<string, string> |
| Enum | enum Name |
status TaskStatus |
| Class | class Name |
カスタム型 |
| Union | type1 \| type2 |
result string \| Error |
関数の属性
| 属性 | 目的 | 例 |
|---|---|---|
@description |
フィールドのドキュメント | @description("ユーザーのメールアドレス") |
@alias |
JSON キーのマッピング | @alias("user_id") |
@skip |
出力から除外 | @skip |
クライアントの選択
// clients.baml でクライアントを定義
client GPT4 {
provider openai
options {
model "gpt-4-turbo"
temperature 0.7
}
}
client Claude {
provider anthropic
options {
model "claude-3-opus"
max_tokens 4096
}
}
// 関数で使用
function MyFunc(input: Input) -> Output {
client GPT4 // または Claude
prompt #"..."#
}
リトライとフォールバック
// リトライを設定
client GPT4WithRetry {
provider openai
retry_policy {
max_retries 3
strategy exponential_backoff
}
}
// フォールバックチェーン
client_fallback MainClient {
primary GPT4
fallback [Claude, GPT35Turbo]
}
ベストプラクティス
1. 型安全性を最優先
常に明示的な型を定義します。
// 良い例: 明示的な型
class BookAnalysis {
title string
author string
summary string @description("2-3 文の要約")
rating float @description("0-5 の評価")
tags string[]
}
// 悪い例: 汎用的な型を使用
function AnalyzeBook(text: string) -> string // 型安全性が失われる
2. 説明を使用する
LLM のガイダンスのために説明を追加します。
class SearchQuery {
query string @description("自然言語でのユーザーの検索クエリ")
filters SearchFilters? @description("結果を絞り込むためのオプションのフィルター")
limit int @description("返す結果の最大数、デフォルトは 10")
}
3. エラーを処理する
エラー型を定義します。
class Error {
code string
m
(原文がここで切り詰められています) 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
BAML Integration Skill
Universal patterns for working with BAML (Boundary ML) in any project. BAML provides type-safe LLM prompting with automatic code generation for Python and TypeScript.
Design Principle
This skill is framework-generic. It provides universal BAML patterns that work in any codebase:
- NOT tailored to CodeGraph-DE, Book-Vetting, or any specific project
- Covers common patterns applicable across all BAML projects
- Specific domain types should go in project-specific skills
Variables
| Variable | Default | Description |
|---|---|---|
| BAML_SRC | baml_src | Directory containing BAML files |
| AUTO_GENERATE | true | Auto-run baml-cli generate on changes |
| STRICT_TYPES | true | Enforce strict type matching |
Instructions
MANDATORY - Follow the Workflow steps below in order.
- Understand BAML's role in the project
- Check existing BAML schema and types
- Follow type-safe patterns when working with LLMs
- Keep generated code in sync
Red Flags - STOP and Reconsider
If you're about to:
- Define LLM prompts without BAML types
- Manually parse LLM output instead of using BAML
- Skip running
baml-cli generateafter schema changes - Ignore type errors in generated clients
STOP -> Define BAML types -> Generate client -> Then proceed
Workflow
1. Understand Project BAML Setup
Check the BAML configuration:
# Find BAML source directory
find . -name "*.baml" -type f | head -5
# Check BAML client
ls -la baml_client/ || ls -la baml_src/baml_client/
# Check for generator config
cat baml_src/generators.baml 2>/dev/null
2. Review Existing Types
Before adding new types, review what exists:
// Common patterns in baml_src/types/
// Enums
enum TaskStatus {
PENDING
IN_PROGRESS
COMPLETED
FAILED
}
// Classes (DTOs)
class UserRequest {
query string
context string?
preferences map<string, string>?
}
class UserResponse {
answer string
confidence float
sources string[]
}
3. Define New Types
When adding LLM-powered features:
// 1. Define input type
class MyInput {
field1 string @description("Clear description")
field2 int @description("What this number represents")
}
// 2. Define output type
class MyOutput {
result string
metadata MyMetadata?
}
class MyMetadata {
confidence float
reasoning string
}
// 3. Define the function
function MyFunction(input: MyInput) -> MyOutput {
client GPT4
prompt #"
Given: {{ input.field1 }}
Count: {{ input.field2 }}
Provide your analysis.
{{ ctx.output_format }}
"#
}
4. Generate Client
After schema changes:
# Generate Python and TypeScript clients
baml-cli generate
# Or with specific config
baml-cli generate --config baml_src/generators.baml
5. Use Generated Client
# Python usage
from baml_client import b
async def process_request(input_data: dict):
result = await b.MyFunction(
input=MyInput(
field1=input_data["query"],
field2=input_data["count"]
)
)
return result.result
// TypeScript usage
import { b } from './baml_client';
async function processRequest(inputData: Record<string, unknown>) {
const result = await b.MyFunction({
field1: inputData.query as string,
field2: inputData.count as number
});
return result.result;
}
Cookbook
Schema Synchronization
- IF: Adding or modifying BAML types
- THEN: Read and execute
./cookbook/schema-sync.md
DTO Generation
- IF: Creating data transfer objects
- THEN: Read and execute
./cookbook/dto-generation.md
Client Wrapper Patterns
- IF: Wrapping BAML client for your service
- THEN: Read and execute
./cookbook/client-wrapper.md
Quick Reference
BAML Type Syntax
| Type | Syntax | Example |
|---|---|---|
| String | string |
name string |
| Int | int |
count int |
| Float | float |
score float |
| Boolean | bool |
active bool |
| Optional | type? |
nickname string? |
| Array | type[] |
tags string[] |
| Map | map<K, V> |
metadata map<string, string> |
| Enum | enum Name |
status TaskStatus |
| Class | class Name |
Custom types |
| Union | type1 \| type2 |
result string \| Error |
Function Attributes
| Attribute | Purpose | Example |
|---|---|---|
@description |
Field documentation | @description("User's email") |
@alias |
JSON key mapping | @alias("user_id") |
@skip |
Exclude from output | @skip |
Client Selection
// Define clients in clients.baml
client GPT4 {
provider openai
options {
model "gpt-4-turbo"
temperature 0.7
}
}
client Claude {
provider anthropic
options {
model "claude-3-opus"
max_tokens 4096
}
}
// Use in functions
function MyFunc(input: Input) -> Output {
client GPT4 // or Claude
prompt #"..."#
}
Retry and Fallback
// Configure retries
client GPT4WithRetry {
provider openai
retry_policy {
max_retries 3
strategy exponential_backoff
}
}
// Fallback chain
client_fallback MainClient {
primary GPT4
fallback [Claude, GPT35Turbo]
}
Best Practices
1. Type Safety First
Always define explicit types:
// Good: Explicit types
class BookAnalysis {
title string
author string
summary string @description("2-3 sentence summary")
rating float @description("Rating from 0-5")
tags string[]
}
// Bad: Using generic types
function AnalyzeBook(text: string) -> string // Loses type safety
2. Use Descriptions
Add descriptions for LLM guidance:
class SearchQuery {
query string @description("The user's search query in natural language")
filters SearchFilters? @description("Optional filters to narrow results")
limit int @description("Maximum number of results to return, default 10")
}
3. Handle Errors
Define error types:
class Error {
code string
message string
}
function SafeAnalysis(input: Input) -> Output | Error {
// LLM can return either success or error
}
4. Version Your Schema
Keep schema versions aligned:
// baml_src/version.baml
// Schema version: 1.2.0
// Last updated: 2025-12-24
// Document breaking changes in CHANGELOG
Integration Points
With Schema Alignment
BAML types should align with database models:
// BAML type
class User {
id int
email string
name string?
}
// Should match SQLAlchemy model
class User(Base):
id: Mapped[int]
email: Mapped[str]
name: Mapped[str | None]
With API Schemas
BAML types can generate API response types:
// BAML response type
class APIResponse {
success bool
data ResponseData
error string?
}
// Use generated types in FastAPI
@app.post("/analyze")
async def analyze(request: Request) -> APIResponse:
result = await b.Analyze(request.data)
return APIResponse(success=True, data=result)
With Frontend Types
Generated TypeScript types work with frontend:
// Generated by BAML
import type { BookAnalysis } from './baml_client/types';
// Use in React component
function BookCard({ analysis }: { analysis: BookAnalysis }) {
return (
<div>
<h2>{analysis.title}</h2>
<p>{analysis.summary}</p>
<Rating value={analysis.rating} />
</div>
);
}
Troubleshooting
Generation Errors
# Check BAML syntax
baml-cli check
# Verbose generation
baml-cli generate --verbose
Type Mismatches
If LLM output doesn't match expected type:
- Check prompt for clarity
- Add more explicit
@descriptionhints - Consider using union types with Error
- Enable strict mode in client
Client Import Issues
# Ensure client is generated
try:
from baml_client import b
except ImportError:
# Run: baml-cli generate
raise RuntimeError("BAML client not generated. Run: baml-cli generate")