No description
Find a file
Piotr Oleszczyk 5bb2ea5f08 feat(api): add short_id column for consistent LLM UUID handling
Resolves validation failures where LLM fabricated full UUIDs from 8-char
prefixes shown in context, causing 'unknown product_id' errors.

Root Cause Analysis:
- Context showed 8-char short IDs: '77cbf37c' (Phase 2 optimization)
- Function tool returned full UUIDs: '77cbf37c-3830-4927-...'
- LLM saw BOTH formats, got confused, invented UUIDs for final response
- Validators rejected fabricated UUIDs as unknown products

Solution: Consistent 8-char short_id across LLM boundary:
1. Database: New short_id column (8 chars, unique, indexed)
2. Context: Shows short_id (was: str(id)[:8])
3. Function tools: Return short_id (was: full UUID)
4. Translation layer: Expands short_id → UUID before validation
5. Database: Stores full UUIDs (no schema change for existing data)

Changes:
- Added products.short_id column with unique constraint + index
- Migration populates from UUID prefix, handles collisions via regeneration
- Product model auto-generates short_id for new products
- LLM contexts use product.short_id consistently
- Function tools return product.short_id
- Added _expand_product_id() translation layer in routines.py
- Integrated expansion in suggest_routine() and suggest_batch()
- Validators work with full UUIDs (no changes needed)

Benefits:
 LLM never sees full UUIDs, no format confusion
 Maintains Phase 2 token optimization (~85% reduction)
 O(1) indexed short_id lookups vs O(n) pattern matching
 Unique constraint prevents collisions at DB level
 Clean separation: 8-char for LLM, 36-char for application

From production error:
  Step 1: unknown product_id 77cbf37c-3830-4927-9669-07447206689d
  (LLM invented the last 28 characters)

Now resolved: LLM uses '77cbf37c' consistently, translation layer
expands to real UUID before validation.
2026-03-06 10:58:26 +01:00
backend feat(api): add short_id column for consistent LLM UUID handling 2026-03-06 10:58:26 +01:00
docs feat(profile): add profile settings and LLM user context 2026-03-05 15:57:21 +01:00
frontend feat(profile): add profile settings and LLM user context 2026-03-05 15:57:21 +01:00
nginx refactor(api): remove MCP server integration and docs references 2026-03-04 12:28:30 +01:00
systemd feat(backend): move product pricing to async persisted jobs 2026-03-04 22:46:16 +01:00
.gitignore fix: load .env via python-dotenv; SQLite default for local dev 2026-02-26 20:51:13 +01:00
AGENTS.md docs(repo): define agent skills and frontend cookbook workflow 2026-03-05 10:49:07 +01:00
deploy.sh feat(backend): move product pricing to async persisted jobs 2026-03-04 22:46:16 +01:00
PHASE1_COMPLETE.md feat(api): add LLM response validation and input sanitization 2026-03-06 10:16:47 +01:00
README.md feat(profile): add profile settings and LLM user context 2026-03-05 15:57:21 +01:00

innercontext

Personal health and skincare data hub. Collects structured data (products, routines, lab results, medications, skin snapshots) and exposes it via a REST API and a web UI to an LLM agent.

Repository layout

backend/    Python backend — FastAPI REST API + SQLModel models
frontend/   SvelteKit web UI (Svelte 5, TypeScript, Tailwind CSS v4)
docs/       Deployment guides
nginx/      nginx config for production
systemd/    systemd service units

Backend quick start

Requirements: Python 3.12+, PostgreSQL, uv

cd backend

# Install dependencies
uv sync

# Set database URL (defaults to postgresql+psycopg://localhost/innercontext)
export DATABASE_URL=postgresql+psycopg://user:password@localhost/innercontext

# Start the API server (creates tables on first run)
uv run uvicorn main:app --reload

API docs available at http://localhost:8000/docs.

Frontend quick start

Requirements: Node.js 24 LTS+, pnpm

cd frontend

# Install dependencies
pnpm install

# Start dev server (proxies API calls to localhost:8000)
pnpm dev

UI available at http://localhost:5173.

API overview

Prefix Resource
/products Skincare / medication products + inventory
/inventory Individual inventory entries
/health/medications Medication entries and usage history
/health/lab-results Lab test results
/routines AM/PM skincare routines and steps
/routines/grooming-schedule Weekly grooming schedule
/skincare Weekly skin condition snapshots
/profile User profile (birth date, sex at birth)
/health-check Liveness probe

Frontend routes

Route Description
/ Dashboard
/products Product list
/products/new Add product
/products/[id] Product detail / edit
/routines Routine list
/routines/new Create routine
/routines/[id] Routine detail
/health/medications Medications
/health/lab-results Lab results
/skin Skin condition snapshots
/profile User profile

Development

cd backend

# Lint
uv run ruff check .

# Format
uv run black .
uv run isort .

# Tests
uv run pytest

Stack

  • Backend: Python 3.12, FastAPI, Uvicorn, SQLModel 0.0.37 + SQLAlchemy, Pydantic v2, PostgreSQL (psycopg3)
  • Frontend: SvelteKit 2, Svelte 5 (Runes), TypeScript, Tailwind CSS v4, shadcn-svelte

Deployment

See docs/DEPLOYMENT.md for a step-by-step guide for a Proxmox LXC setup (Debian 13, nginx, systemd services).