# AI, SQL, and GraphQL Walk into a Fertility Clinic… LLM-based development

- Speaker: [Shirli Di Castro Shashua](/wiki/speakers/shirli-di-castro-shashua.md)
- Event: [Reversim Summit 2024](/wiki/years/2024.md)
- Video: https://www.youtube.com/watch?v=LU4nMmgBoCc
- Transcript: [/transcripts/2024/12-LU4nMmgBoCc.md](/transcripts/2024/12-LU4nMmgBoCc.md)
- Language: Hebrew · Type: talk · Level: intermediate
- Topics: [AI and LLMs](/wiki/topics/generative-ai.md), [Machine Learning](/wiki/topics/machine-learning.md), [Architecture](/wiki/topics/architecture.md), [Software Engineering](/wiki/topics/software-engineering.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

The speaker shares the journey of developing a generative AI tool for a fertility tech startup, allowing medical staff to query patient data using natural language. After evaluating direct database queries with SQL and REST APIs, the development team discovered that combining large language models with GraphQL provides the ideal balance of flexibility, security, and precision. The talk details how GraphQL schemas and resolvers empower the AI safely while maintaining strict control over medical data and privacy. Ultimately, the audience learns how to design secure and reliable LLM-driven architectures for domain-specific applications.

## Key points

- [4:10](https://www.youtube.com/watch?v=LU4nMmgBoCc&t=250s) The primary challenge in fertility clinics is enabling doctors to query scattered medical data easily.
- [8:10](https://www.youtube.com/watch?v=LU4nMmgBoCc&t=490s) The development team faced requirements for a flexible, natural language tool that ensures strict data security.
- [13:00](https://www.youtube.com/watch?v=LU4nMmgBoCc&t=780s) Large language models are introduced to bridge the gap between free-form medical questions and database queries.
- [19:25](https://www.youtube.com/watch?v=LU4nMmgBoCc&t=1165s) Using direct SQL generation with LLMs was rejected due to severe risks of system crashes and security violations.
- [19:25](https://www.youtube.com/watch?v=LU4nMmgBoCc&t=1165s) REST APIs were also dismissed because of extreme over-fetching and under-fetching issues.
- [19:25](https://www.youtube.com/watch?v=LU4nMmgBoCc&t=1165s) GraphQL was chosen because its schema, exact fetching, and resolvers provide the necessary security, routing, and flexibility.
- [20:27](https://www.youtube.com/watch?v=LU4nMmgBoCc&t=1227s) Prompt engineering techniques, such as few-shot examples and schema injection, help the LLM generate accurate GraphQL queries.
- [22:30](https://www.youtube.com/watch?v=LU4nMmgBoCc&t=1350s) Robust validations on both the generated queries and final outputs ensure safety and data integrity.

## Takeaways

- Combine large language models with GraphQL instead of direct SQL or REST to ensure secure and flexible data retrieval.
- Use resolvers to handle complex cross-database joins, permissions, and data filtering away from the LLM.
- Implement multi-layer validation, including syntax checks and output comparisons, to maintain trust in AI-generated responses.

## Questions this talk answers

- How can you safely allow an LLM to query internal databases without risking system stability or exposing sensitive data?
- Why is GraphQL a better fit than REST APIs for LLM-driven query generation?
- How do you implement resolvers to handle data privacy and permissions in a medical application?

## Technologies

GraphQL, SQL

## Tags

backend architecture, generative ai, graphql, healthcare tech, llm, security
