Linkml schema

From kbaseincubator/BERIL-research-observatory · View interactive version

Linkml schema is an AI agent skill from the GitHub repository kbaseincubator/BERIL-research-observatory. Generate LinkML schema YAML from markdown, Excel, or text descriptions. Scaffold a LinkML project repo and push to GitHub.

How to use this skill

Skill file

LinkML Schema Generator Skill

Overview

Convert informal data descriptions (markdown tables, Excel spreadsheets, plain text) into formal LinkML schema YAML. Optionally scaffold a full LinkML project repo and push it to GitHub.

Workflow

Execute phases sequentially. Phases 4 and 5 are optional — offer them after Phase 3 succeeds.


Phase 1 — Environment Setup

  1. Check python3 is available (command -v python3). If missing, stop and report.
  2. Check for linkml and openpyxl Python packages:

```bash

python3 -c "import linkml" 2>/dev/null && echo "linkml OK" || echo "linkml MISSING"

python3 -c "import openpyxl" 2>/dev/null && echo "openpyxl OK" || echo "openpyxl MISSING"

```

  1. Auto-install missing packages:
  1. Do not check for copier or gh yet — only check those lazily in Phases 4/5.

Phase 2 — Input Parsing & Schema Inference

  1. Read reference files first:
  1. Identify inputs — ask the user or detect from context. Supported formats:

```python

import openpyxl, json

wb = openpyxl.load_workbook("INPUT.xlsx", data_only=True)

result = {}

for sheet in wb.sheetnames:

ws = wb[sheet]

headers = [c.value for c in ws[1] if c.value]

rows = []

for row in ws.iter_rows(min_row=2, max_col=len(headers), values_only=True):

rows.append(list(row))

result[sheet] = {"headers": headers, "sample_rows": rows[:20]}

print(json.dumps(result, indent=2, default=str))

```

  1. Merge inputs when multiple files are provided. Prefer Excel-inferred types over markdown/text guesses. Deduplicate classes by name similarity.
  1. Interactive review via AskUserQuestion:

Phase 3 — Schema Generation

  1. Build the schema YAML using Python to ensure correct formatting:

```python

import yaml

schema = {

"id": f"https://w3id.org/{schema_name}",

"name": schema_name,

"prefixes": {

"linkml": "https://w3id.org/linkml/",

schema_name: f"https://w3id.org/{schema_name}/",

},

"imports": ["linkml:types"],

"default_range": "string",

"classes": { ... },

"enums": { ... },

}

with open(output_path, "w") as f:

yaml.dump(schema, f, default_flow_style=False, sort_keys=False, allow_unicode=True)

```

  1. Naming conventions:
  1. Validate the generated schema:

```bash

linkml-validate -s SCHEMA.yaml

```

  1. Present results to the user:

Phase 4 — Project Scaffolding (optional)

  1. Read references/copier-template-guide.md.
  2. Check and install copier if missing:

```bash

python3 -c "import copier" 2>/dev/null || pip install copier

```

  1. Ask for project metadata via AskUserQuestion:
  1. Run copier:

```bash

copier copy --trust \

--data project_name=NAME \

--data github_org=ORG \

--data full_name="AUTHOR" \

--data license=LICENSE \

gh:linkml/linkml-project-copier ./PROJECT_DIR

```

  1. Place the generated schema at src/{project_name}/schema/{schema_name}.yaml.
  2. Validate within project context:

```bash

cd PROJECT_DIR && linkml-validate -s src//schema/.yaml

```

  1. Fallback: if copier fails (network, template version mismatch), offer to create a minimal project structure manually:

```

PROJECT_DIR/

├── src/{project_name}/schema/{schema_name}.yaml

├── project/

│ └── .gitkeep

├── pyproject.toml (minimal LinkML project config)

└── Makefile (gen-project, test, lint targets)

```


Phase 5 — GitHub Push (optional)

  1. Check gh is installed and authenticated:

```bash

command -v gh && gh auth status

```

If not authenticated, stop and tell the user to run gh auth login.

  1. Ask via AskUserQuestion:
  1. Create repo and push:

```bash

cd PROJECT_DIR

gh repo create ORG/REPO --VISIBILITY --source=. --remote=origin

git init

git add .

git commit -m "Initial LinkML schema: SCHEMA_NAME"

git branch -M main

git push -u origin main

```

  1. Report final URL and next steps:

Error Handling

| Tier | Examples | Action |

|------|----------|--------|

| Blocking | python3 missing, input file not found, gh not authenticated | Stop and report clearly |

| Recoverable | pip package missing, YAML validation error, copier failure | Auto-fix / retry up to 3 times, then fallback |

| Ambiguous | Unclear class names, type ambiguity, naming conflicts | Ask user via AskUserQuestion |

Safety Rules

  1. Never overwrite existing files without asking first.
  2. Never push to GitHub without explicit user confirmation.
  3. Always validate generated schemas before presenting them as complete.
  4. Use --trust with copier only after confirming the template source with the user.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.