All 12 pieces Piece 04
TikTok Shop video pipeline on free AI models, with a claim gate
Python pipeline that writes TikTok Shop scripts on free models, blocks 19 risky claim patterns and renders 1080x1920 videos. 31 of 32 tests pass.
Built with: Python, OmniRoute and Ollama (qwen3:8b, llama3.2:3b), edge-tts, ffmpeg, SQLite, systemd user timer. Built with AI assistance (Claude) under my direction.
Skills shown: Python, LLM routing and fallback, Prompt design, Content compliance, ffmpeg, Automated testing, Performance feedback loops
Status: Work sample. Built for my own TikTok Shop affiliate work. It makes ready-to-post kits, but I have not posted any yet, so there are no sales results.
In 60 seconds
- Problem: TikTok Shop affiliate income depends on posting good product videos often. Doing that by hand takes hours, and AI-written scripts can slip in health or income claims that break platform rules and put the account at risk.
- What I built: A daily pipeline. It ranks products from Affiliate Center data, writes three hook types per product on free models with automatic fallback, voices them, cuts vertical videos from my own phone clips with word-timed captions, adds
#ad, builds a link page and writes a posting kit. It learns which hooks sell from weekly metrics. - Proof:
python -m unittest discover -s testsruns 32 tests with fake model servers and needs no network. An offline test run today (stub scripts, no model) produced 3 videos at 1080x1920, 17.4 to 18.2 seconds. - Result: 31 of 32 tests pass. The failure is the end-to-end self-test reporting that the
edge_ttsvoice package is not installed in this sandbox. The compliance gate blocks 19 patterns of risky claim before a script reaches a video.
The business problem
TikTok Shop pays creators a commission on products sold through their videos. The work is repetitive: pick products that pay and sell, write a hook that stops the scroll, film, edit, caption, post, and see what worked. For one person, the bottleneck is volume and consistency, not ideas.
AI can write scripts all day, but two things go wrong:
- Rule-breaking claims. Think "cures", "lose 10 pounds", "changed my life" or "only 3 left". Claims like these can break platform rules, and a fake personal testimonial misleads buyers.
- Fragile automation. Free AI endpoints go down, rate-limit or return broken JSON. A pipeline that dies when one model hiccups produces nothing on the days it matters.
What I built
- Productsweekly Affiliate Center CSV, filtered by price, commission, rating, blocked categories
- Rankproducts scored and weighted toward hooks and categories that converted
- Script3 hook types per product on free models, strict JSON
- Gatecompliance check drops any variant with a banned claim
- Voiceedge-tts voice, silent-track fallback if the voice service fails
- Cut1080x1920 video from my own 3 to 6 second phone clips
- Captionburned-in captions timed to the voice word by word
- Kitcaption with #ad, link page, POST_ME.md with the AI-label reminder
- Learnweekly metrics CSV updates the hook and category weights
Model routing with fallback. Each task has an ordered chain. Script writing tries OmniRoute's free combo first, then local qwen3:8b, then local llama3.2:3b; captions start on the faster llama3.2:3b. A model that is down, rate-limited or returns broken JSON is skipped for the next. A wrong model name is corrected from the server's own model list. A free_only setting means it can never switch to a paid model, and a cache makes a repeated prompt cost nothing. If every model is down, the run logs it and skips that product instead of crashing.
The compliance gate. scripts.py checks every hook, body, call to action and overlay against 19 banned patterns before rendering: medical words (cure, heal, clinically, FDA, "doctors recommend"), weight and income promises, fake personal use ("I've been using it for months", "my wife swears by it"), fake scarcity ("only 3 left", "selling out") and absolutes ("100% safe", "no side effects"). A variant with any hit is dropped. Every caption keeps #ad, and a test makes sure no model can remove it.
Human in the loop on purpose. The machine does not post. I upload, paste the caption, turn on TikTok's AI-generated label and attach the product link, at most 3 posts a day. That keeps a person accountable for every public post.
Proof you can check
- Test run today (
evidence/04-ugc-test-run-2026-12-04.txt): "Ran 32 tests in 22.405s, FAILED (failures=1)". The failing test istest_selftest_passes_with_fake_models, whose report says "[FAIL] Python packages: missing edge_tts". I could not install that package in this sandbox. With only that package check skipped, the same test passes, so the full self-test with real voice runs on my laptop. - What the tests cover: broken and chatty model replies, all models down, rate-limit retry, wrong model names healing, the free-only rule, the cache, blocked claims and plain claims allowed,
#adalways kept, captions synced to word timings, the timer setup and the daily run surviving dead models. - Real output today: 3 videos from an offline run with sample products and stub scripts, checked with ffprobe: 1080x1920 H.264 with AAC audio, 18.2, 18.1 and 17.4 seconds. Because the voice package was missing, the audio track is silent and the captions are evenly spaced, not word-timed. Two of the three use a placeholder background because no product clips were supplied. The run log flags each of these. Two frames are in
pieces/04-assets/.
Outcome
Measured
- 31 of 32 automated tests pass; the 1 failure is an environment gap, named above.
- 3 vertical test videos with captions and a posting kit from one offline run (silent track, stub scripts).
- 19 banned-claim patterns enforced in code before rendering.
Projected
- At the 3-posts-a-day cap, about 90 videos a month for roughly 1 minute of my time per post plus about 5 minutes of filming per new product (time estimates from the project README). That is a plan, not a result, until I post and import real metrics.
What I would do next
- Run the full self-test on the laptop, then post the first 3 kits and import metrics after 7 days.
- Report which hook type earns the most per 1,000 views once there are 30 or more posts.
- Add a second gate: a separate model rereads each script for implied claims the pattern list cannot catch.


Frames from the offline test run described above. Placeholder footage, not posted content.
Files you can open
Everything this piece points to. Scripts run with Python 3; see each piece for the exact command.