My dog Biscuit has been acting weird for weeks. Tail low, ears back, avoiding his food bowl like it owed him money.
I Googled everything. Got 47 different answers. Half said "normal." Half said "vet, immediately."
So I did what any developer would do: I built an AI to figure it out.
Here's exactly how — and why it works better than panicking on Reddit at 2am.
The Problem With "Is My Pet Okay?"
Vets are expensive. Google is terrifying. And most pet symptom checkers are glorified FAQ pages from 2009.
What if you could describe your pet's behavior in plain English and get an actual intelligent response — not just a symptom list?
That's exactly what I built.
The Stack
- Python 3.11
- OpenAI GPT-4o (with vision for photo analysis)
- FastAPI for the backend
- A carefully engineered system prompt (this is the secret sauce)
Step 1: The System Prompt (Don't Skip This)
Most AI pet tools fail because their prompts are garbage. Here's what actually works:
SYSTEM_PROMPT = """
You are a veterinary behavior analyst with 15+ years of experience.
Your job is to help pet owners understand their animal's behavior and emotional state.
Guidelines:
- Ask clarifying questions if the description is vague
- Distinguish between behavioral issues and potential medical symptoms
- Always recommend a vet visit for anything that could be physical
- Provide actionable steps the owner can take TODAY
- Use empathetic, non-alarmist language
- Reference specific animal behavior research when relevant
You are NOT replacing a vet. You are helping owners be better prepared.
"""
The key insight: tell the model what it is, what it should avoid, and what success looks like.
Step 2: The Behavior Analysis Engine
import openai
from fastapi import FastAPI
from pydantic import BaseModel
client = openai.OpenAI(api_key="your-key-here")
app = FastAPI()
class PetQuery(BaseModel):
pet_type: str # "dog", "cat", "rabbit", etc.
age_years: float
description: str
duration: str # "since this morning", "3 days", etc.
@app.post("/analyze")
async def analyze_behavior(query: PetQuery):
user_message = f"""
Pet: {query.pet_type}, {query.age_years} years old
Behavior change: {query.description}
Duration: {query.duration}
Please analyze this and tell me:
1. What this behavior likely means
2. Whether I need to see a vet urgently
3. What I can do right now to help
"""
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message}
],
temperature=0.4, # Lower = more consistent, less hallucination
max_tokens=800
)
return {
"analysis": response.choices[0].message.content,
"model": "gpt-4o",
"tokens_used": response.usage.total_tokens
}
Step 3: Add Vision (The Game-Changer)
Text descriptions are limited. A photo is worth a thousand symptoms.
import base64
from pathlib import Path
def encode_image(image_path: str) -> str:
with open(image_path, "rb") as f:
return base64.b64encode(f.read()).decode("utf-8")
@app.post("/analyze-with-photo")
async def analyze_with_photo(image_path: str, description: str, pet_type: str):
base64_image = encode_image(image_path)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{
"role": "user",
"content": [
{
"type": "text",
"text": f"This is my {pet_type}. Here's what I've noticed: {description}. What do you see in this photo that might be relevant?"
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}",
"detail": "high"
}
}
]
}
],
max_tokens=1000
)
return {"analysis": response.choices[0].message.content}
What I Learned (The Hard Way)
1. Temperature matters more than model. GPT-4o at temperature 0.3 beats GPT-4o at 0.9 for medical/behavioral accuracy. High temp = creative but wrong.
2. Context is everything. Age, breed, recent changes (new food? new baby? moved house?) dramatically change the interpretation. Collect it.
3. Never suppress the vet recommendation. I tried to filter it out to reduce anxiety. Bad idea. Users actually trust the tool MORE when it tells them to see a vet.
4. Conversation memory changes outcomes. A single-turn query misses 40% of relevant context. Build a multi-turn conversation.
Results
Biscuit? Turns out he was anxious about a new neighbor's dog he could hear through the fence. The AI flagged it as separation-adjacent anxiety within 30 seconds. Vet confirmed it. $0 consultation vs $180 emergency visit.
Not bad for 87 lines of Python.
Want This Without Building It?
If you'd rather use a polished version with multi-modal support, conversation memory, and breed-specific insights already baked in — check out MyPetTherapist.com. It's what this project eventually became.
But honestly? Build it yourself first. You'll learn more about prompt engineering from one pet behavior project than from any tutorial.
What's the most surprising thing your pet has done that turned out to have a simple explanation? Drop it in the comments — I'm collecting these for a dataset 👇
Top comments (0)